Class: Klear::Frame
- Inherits:
-
Object
- Object
- Klear::Frame
- Defined in:
- lib/klear/frame.rb
Instance Attribute Summary collapse
-
#column_count ⇒ Object
readonly
Returns the value of attribute column_count.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#row_count ⇒ Object
readonly
Returns the value of attribute row_count.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
- #cell(x, y) ⇒ Object
- #column(no) ⇒ Object (also: #blade)
- #each_cell(&blk) ⇒ Object
- #each_column(&blk) ⇒ Object (also: #each_blade, #columns)
-
#each_row(&blk) ⇒ Object
(also: #rows)
returns array of rows.
-
#initialize(column_count, row_count, data = nil) ⇒ Frame
constructor
A new instance of Frame.
- #row(no) ⇒ Object
Constructor Details
#initialize(column_count, row_count, data = nil) ⇒ Frame
Returns a new instance of Frame.
5 6 7 8 9 |
# File 'lib/klear/frame.rb', line 5 def initialize column_count, row_count, data = nil @row_count, @column_count = row_count, column_count @size = @row_count * @column_count @data = data end |
Instance Attribute Details
#column_count ⇒ Object (readonly)
Returns the value of attribute column_count.
3 4 5 |
# File 'lib/klear/frame.rb', line 3 def column_count @column_count end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/klear/frame.rb', line 3 def data @data end |
#row_count ⇒ Object (readonly)
Returns the value of attribute row_count.
3 4 5 |
# File 'lib/klear/frame.rb', line 3 def row_count @row_count end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/klear/frame.rb', line 3 def size @size end |
Instance Method Details
#cell(x, y) ⇒ Object
11 12 13 |
# File 'lib/klear/frame.rb', line 11 def cell x, y column(x)[y] end |
#column(no) ⇒ Object Also known as: blade
49 50 51 52 53 54 55 |
# File 'lib/klear/frame.rb', line 49 def column no col = [] (0...@row_count).each do |curRow| col << @data[no + curRow * @column_count] end col end |
#each_cell(&blk) ⇒ Object
15 16 17 18 19 |
# File 'lib/klear/frame.rb', line 15 def each_cell &blk each_row do |row, y| row.each_with_index {|val, x| blk.call(val, x, y)} end end |
#each_column(&blk) ⇒ Object Also known as: each_blade, columns
58 59 60 61 62 63 64 65 66 |
# File 'lib/klear/frame.rb', line 58 def each_column &blk @columns ||= (0...@column_count).map {|n| column(n)} if block_given? @columns.each_with_index {|column, idx| blk.call(column, idx)} end @columns end |
#each_row(&blk) ⇒ Object Also known as: rows
returns array of rows
38 39 40 41 42 43 44 45 46 |
# File 'lib/klear/frame.rb', line 38 def each_row &blk @rows ||= (0...@row_count).map {|n| row(n)} if block_given? @rows.each_with_index {|row, idx| blk.call(row, idx)} end @rows end |
#row(no) ⇒ Object
21 22 23 |
# File 'lib/klear/frame.rb', line 21 def row no @data.slice(no * @column_count, @column_count) end |