Class: Fastsheet::Sheet
- Inherits:
-
Object
- Object
- Fastsheet::Sheet
- Defined in:
- lib/fastsheet/sheet.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #column(n) ⇒ Object
- #columns ⇒ Object
- #each_column ⇒ Object
- #each_row ⇒ Object
-
#initialize(file_name, options = {}) ⇒ Sheet
constructor
A new instance of Sheet.
- #row(n) ⇒ Object
Constructor Details
#initialize(file_name, options = {}) ⇒ Sheet
Returns a new instance of Sheet.
7 8 9 10 11 12 |
# File 'lib/fastsheet/sheet.rb', line 7 def initialize(file_name, = {}) # this method sets @rows, @height and @width read!(file_name) @header = @rows.shift if [:header] end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
3 4 5 |
# File 'lib/fastsheet/sheet.rb', line 3 def file_name @file_name end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
3 4 5 |
# File 'lib/fastsheet/sheet.rb', line 3 def header @header end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
3 4 5 |
# File 'lib/fastsheet/sheet.rb', line 3 def height @height end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
3 4 5 |
# File 'lib/fastsheet/sheet.rb', line 3 def rows @rows end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
3 4 5 |
# File 'lib/fastsheet/sheet.rb', line 3 def width @width end |
Instance Method Details
#column(n) ⇒ Object
26 27 28 |
# File 'lib/fastsheet/sheet.rb', line 26 def column(n) @rows.map { |r| r[n] } end |
#columns ⇒ Object
30 31 32 33 34 |
# File 'lib/fastsheet/sheet.rb', line 30 def columns (0...@width).inject([]) do |cols, i| cols.push column(i) end end |
#each_column ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/fastsheet/sheet.rb', line 36 def each_column if block_given? columns.each { |c| yield c } else columns.each end end |
#each_row ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/fastsheet/sheet.rb', line 18 def each_row if block_given? @rows.each { |r| yield r } else @rows.each end end |
#row(n) ⇒ Object
14 15 16 |
# File 'lib/fastsheet/sheet.rb', line 14 def row(n) @rows[n] end |