Changeset 207 for ruby


Ignore:
Timestamp:
Aug 16, 2009, 7:14:16 PM (15 years ago)
Author:
KOBAYASHI, Shinji
Message:

refs #54

Location:
ruby/branches/0.5
Files:
3 edited

Legend:

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

    r203 r207  
    5757
    5858          def ith_item(i)
    59             return @items[i]
     59            raise ArgumentError, 'index invalid' if i <= 0
     60            return @items[i - 1]
    6061          end
    6162
     
    8283            end
    8384          end
     85
     86          def column_count
     87            if @rows.nil?
     88              return 0
     89            else
     90              return @rows[0].items.count
     91            end
     92          end
     93
     94          def row_names
     95            if @rows.nil?
     96              return []
     97            else
     98              return @rows.collect{|r| r.name}
     99            end
     100          end
     101
     102          def column_names
     103            if @rows.nil?
     104              return []
     105            else
     106              return @rows[0].items.collect{|i| i.name}
     107            end
     108          end
     109
     110          def ith_row(i)
     111            raise ArgumentError, 'invalid index' if i<=0 or i>@rows.size
     112            if @rows.nil?
     113              return []
     114            else
     115              return @rows[i - 1]
     116            end
     117          end
    84118        end
    85119      end # of ItemStructure
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/item_structure/item_list_spec.rb

    r205 r207  
    4040
    4141  it 'retrieve the ith item with number' do
    42     @item_list.ith_item(1).name.value.should == 'two'
     42    @item_list.ith_item(1).name.value.should == 'one'
    4343  end
    4444
  • ruby/branches/0.5/spec/lib/open_ehr/rm/data_structures/item_structure/item_table_spec.rb

    r206 r207  
    3232  end
    3333
    34   it 'row count should be 2' do
     34  it 's row count should be 2' do
    3535    @item_table.row_count.should be_equal 2
    3636  end
    3737
    38   it 'column_count should be 3' do
     38  it 's row_count should be 0 when rows are nil' do
     39    @item_table.rows = nil
     40    @item_table.row_count.should be_equal 0
     41  end
     42
     43  it 's column_count should be 3' do
    3944    @item_table.column_count.should be_equal 3
    4045  end
    4146
    42   it 'row_names should be cluster cluster' do
     47
     48  it 's row_names should be cluster cluster' do
    4349    @item_table.row_names.should == %w{cluster cluster}.collect{|n| DvText.new(n)}
    4450  end
     51
     52  it 's row_names should be empty when items are nil' do
     53    @item_table.rows = nil
     54    @item_table.row_names.should == []
     55  end
     56
     57  it 's column_names should one two three' do
     58    @item_table.column_names.should == %w{one two three}.collect{|s| DvText.new(s)}
     59  end
     60
     61  it 's column_names should empty when items aer nil' do
     62    @item_table.rows = nil
     63    @item_table.column_names.should == []
     64  end
     65
     66  it 's ith_row(integer) should be ith row' do
     67    @item_table.ith_row(2).items[1].name.value.should == 'five'
     68  end
     69
     70  it 'should be invalid index under 0' do
     71    lambda {@item_table.ith_row(0) }.should raise_error(ArgumentError)
     72  end
    4573end
Note: See TracChangeset for help on using the changeset viewer.