Changeset 195
- Timestamp:
- Aug 14, 2009, 8:11:44 PM (15 years ago)
- Location:
- ruby/branches/0.5
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ruby/branches/0.5/lib/open_ehr/rm/data_structures/item_structure.rb
r194 r195 32 32 attr_accessor :items 33 33 34 def initialize(args = {}) 35 super(args) 36 self.items = args[:items] 37 end 38 34 39 def item_count 35 40 unless @items.nil? … … 39 44 end 40 45 end 46 47 def names 48 return @items.collect{|item| item.name} 49 end 50 51 def named_item(a_name) 52 @items.each do |item| 53 return item if item.name.value == a_name 54 end 55 retrun nil 56 end 57 58 def ith_item(i) 59 return @items[i] 60 end 61 62 def as_hierarchy 63 return Cluster.new(:name => @name, 64 :archetype_node_id => @archetype_node_id, 65 :items => @items) 66 end 41 67 end 42 68 end # of ItemStructure -
ruby/branches/0.5/lib/open_ehr/rm/data_types/basic.rb
r167 r195 11 11 class DataValue 12 12 include OpenEhr::RM::Support::Definition::BasicDefinition 13 def ==(other) 14 return self.value == other.value 15 end 13 16 end 14 17 … … 25 28 end 26 29 end 30 27 31 def value? 28 32 @value == true -
ruby/branches/0.5/spec/lib/openehr/rm/data_structure/item_structure/item_list_spec.rb
r194 r195 1 1 require File.dirname(__FILE__) + '/../../../../../spec_helper' 2 2 include OpenEhr::RM::DataStructures::ItemStructure 3 include OpenEhr::RM::DataStructures::ItemStructure::Representation 3 4 include OpenEhr::RM::DataTypes::Text 4 5 5 6 describe ItemList do 6 7 before(:each) do 8 items = %w{one two three}.collect do |n| 9 Element.new(:name => DvText.new(n), 10 :archetype_node_id => 'test') 11 end 7 12 item_list_name = DvText.new('item list') 8 13 @item_list = ItemList.new(:name => item_list_name, 9 :archetype_node_id => 'test') 14 :archetype_node_id => 'test', 15 :items => items) 16 10 17 end 11 18 … … 14 21 end 15 22 16 it 'count should be 0' do17 @item_list.item_count.should equal 023 it 'count should be 3' do 24 @item_list.item_count.should be_equal 3 18 25 end 19 26 20 it 'count should be change to 3' do 21 dummy_elements = [1,2,3] 22 @item_list.items = dummy_elements 23 @item_list.item_count.should equal 3 27 it 'count should be 0' do 28 @item_list.items = nil 29 @item_list.item_count.should be_equal 0 30 end 31 32 33 it 'retrieve the names of all items' do 34 @item_list.names.should == %w{one two three}.collect{|n| DvText.new(n)} 35 end 36 37 it 'retrieve the item with a name' do 38 @item_list.named_item('one').name.value.should == 'one' 39 end 40 41 it 'retrieve the ith item with number' do 42 @item_list.ith_item(1).name.value.should == 'two' 43 end 44 45 it 'generate cluster of items' do 46 @item_list.as_hierarchy.name.value.should == 'item list' 24 47 end 25 48 end
Note:
See TracChangeset
for help on using the changeset viewer.