Changeset 340


Ignore:
Timestamp:
Nov 10, 2009, 10:45:54 PM (14 years ago)
Author:
KOBAYASHI, Shinji
Message:

item structure is completed

Location:
ruby/branches/0.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • ruby/branches/0.5/lib/open_ehr/rm/data_structures/item_structure.rb

    r339 r340  
    186186            self.items = args[:items]
    187187          end
     188
     189          def has_element_path?(path)
     190            paths = [ ]
     191            @items.each do |item|
     192              paths << item.archetype_node_id
     193            end
     194            return paths.include? path
     195          end
     196
     197          def element_at_path(path)
     198            @items.each do |item|
     199              return item if item.archetype_node_id == path
     200            end
     201            return nil
     202          end
     203
     204          def as_hierarchy
     205            return Cluster.new(:name => @name,
     206                               :archetype_node_id => @archetype_node_id,
     207                               :items => @items)
     208          end
    188209        end
    189210      end # of ItemStructure
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/item_structure/item_tree_spec.rb

    r220 r340  
    77describe ItemTree do
    88  before(:each) do
    9     items = %w{one two}.collect do |name|
     9    i = 1
     10    items = %w{one two three}.collect do |name|
     11      i += 1
    1012      Element.new(:name => DvText.new(:value => name),
    11                   :archetype_node_id => 'test')
     13                  :archetype_node_id => 'at000' + i.to_s)
    1214    end
    1315    name = DvText.new(:value => 'item tree')
    1416    @item_tree = ItemTree.new(:name => name,
    15                               :archetype_node_id => 'test',
     17                              :archetype_node_id => 'at0001',
    1618                              :items => items)
    1719  end
     
    2628
    2729  it 'has valid element path' do
     30    @item_tree.has_element_path?('at0002').should be_true
     31  end
     32
     33  it 'should return false with wrong node' do
     34    @item_tree.has_element_path?('at0005').should be_false
     35  end
     36
     37  it 'path at002 should return two' do
     38    @item_tree.element_at_path('at0003').name.value.should == 'two'
     39  end
     40
     41  it 'path at005 should return nil' do
     42    @item_tree.element_at_path('at0005').should be_nil
     43  end
     44
     45  it 'should returns ItemTree as Cluster' do
     46    @item_tree.as_hierarchy.name.value.should == 'item tree'
    2847  end
    2948end
Note: See TracChangeset for help on using the changeset viewer.