Class: Pulo::FrameRow
- Inherits:
-
Object
- Object
- Pulo::FrameRow
- Defined in:
- lib/pulo/frames/frame_row.rb
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#row_number ⇒ Object
Returns the value of attribute row_number.
Instance Method Summary collapse
- #[](column) ⇒ Object
- #append_column(cell) ⇒ Object
- #delete_column(index) ⇒ Object
- #first_row? ⇒ Boolean
-
#initialize(parent_frame, row_number) ⇒ FrameRow
constructor
A new instance of FrameRow.
- #inspect ⇒ Object
- #next_row ⇒ Object
- #next_rows ⇒ Object
- #previous_row ⇒ Object
- #previous_rows ⇒ Object
- #to_a ⇒ Object
- #to_a_values ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #value_cells ⇒ Object
Constructor Details
#initialize(parent_frame, row_number) ⇒ FrameRow
5 6 7 8 9 |
# File 'lib/pulo/frames/frame_row.rb', line 5 def initialize(parent_frame, row_number) @cells=[] @parent_frame=parent_frame @row_number=row_number end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
3 4 5 |
# File 'lib/pulo/frames/frame_row.rb', line 3 def cells @cells end |
#row_number ⇒ Object
Returns the value of attribute row_number.
4 5 6 |
# File 'lib/pulo/frames/frame_row.rb', line 4 def row_number @row_number end |
Instance Method Details
#[](column) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/pulo/frames/frame_row.rb', line 19 def [](column) if column.is_a?(Integer) raise IndexError,"No column number #{column} defined." unless @cells[column] @cells[column] else @parent_frame[column][@row_number] end end |
#append_column(cell) ⇒ Object
11 12 13 |
# File 'lib/pulo/frames/frame_row.rb', line 11 def append_column(cell) @cells<<cell end |
#delete_column(index) ⇒ Object
15 16 17 |
# File 'lib/pulo/frames/frame_row.rb', line 15 def delete_column(index) @cells.delete_at index end |
#first_row? ⇒ Boolean
83 84 85 |
# File 'lib/pulo/frames/frame_row.rb', line 83 def first_row? @row_number==0 end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/pulo/frames/frame_row.rb', line 63 def inspect "Frame Row Object" end |
#next_row ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/pulo/frames/frame_row.rb', line 52 def next_row if @row_number<@parent_frame.row_count @parent_frame.rows[@row_number+1] else nil end end |
#next_rows ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/pulo/frames/frame_row.rb', line 36 def next_rows Enumerator.new do |y| for i in (@row_number+1)..@parent_frame.row_count-1 y.yield @parent_frame.rows[i] end end end |
#previous_row ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/pulo/frames/frame_row.rb', line 44 def previous_row if @row_number>0 @parent_frame.rows[@row_number-1] else nil end end |
#previous_rows ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/pulo/frames/frame_row.rb', line 28 def previous_rows Enumerator.new do |y| for i in (0..(@row_number-1)).reverse_each y.yield @parent_frame.rows[i] end end end |
#to_a ⇒ Object
67 68 69 |
# File 'lib/pulo/frames/frame_row.rb', line 67 def to_a @cells.map {|cell| cell.value} end |
#to_a_values ⇒ Object
71 72 73 |
# File 'lib/pulo/frames/frame_row.rb', line 71 def to_a_values value_cells.map {|cell| cell.value} end |
#to_h ⇒ Object
79 80 81 |
# File 'lib/pulo/frames/frame_row.rb', line 79 def to_h Hash[@parent_frame.column_names.keys.to_a.zip(to_a)] end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/pulo/frames/frame_row.rb', line 60 def to_s "row #{@row_number}:".ljust(9,' ') + " #{((@cells.select {|s| !s.column.hidden?}).map {|c| c.to_s}).join(' ')}" end |
#value_cells ⇒ Object
75 76 77 |
# File 'lib/pulo/frames/frame_row.rb', line 75 def value_cells @cells.find_all { |cell| cell.value_column?} end |