Class: Worksheet
- Inherits:
-
Object
- Object
- Worksheet
- Defined in:
- lib/solis/shape/reader/simple_sheets/worksheet.rb
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#spreadsheet ⇒ Object
readonly
Returns the value of attribute spreadsheet.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #gid ⇒ Object
-
#initialize(spreadsheet, properties) ⇒ Worksheet
constructor
A new instance of Worksheet.
-
#num_cols ⇒ Object
Column number of the right-most non-empty column.
- #num_rows ⇒ Object
- #rows(skip = 0) ⇒ Object
- #sheet_id ⇒ Object
Constructor Details
#initialize(spreadsheet, properties) ⇒ Worksheet
Returns a new instance of Worksheet.
4 5 6 7 8 9 10 11 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 4 def initialize(spreadsheet, properties) @spreadsheet = spreadsheet set_properties(properties) @cells = nil @input_values = nil @numeric_values = nil @modified = Set.new end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
2 3 4 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 2 def properties @properties end |
#spreadsheet ⇒ Object (readonly)
Returns the value of attribute spreadsheet.
2 3 4 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 2 def spreadsheet @spreadsheet end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
2 3 4 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 2 def title @title end |
Instance Method Details
#[](*args) ⇒ Object
21 22 23 24 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 21 def [](*args) (row, col) = parse_cell_args(args) cells[[row, col]] || '' end |
#gid ⇒ Object
17 18 19 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 17 def gid sheet_id.to_s end |
#num_cols ⇒ Object
Column number of the right-most non-empty column.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 47 def num_cols reload_cells unless @cells # Memoizes it because this can be bottle-neck. # https://github.com/gimite/google-drive-ruby/pull/49 @num_cols ||= @input_values .reject { |(_r, _c), v| v.empty? } .map { |(_r, c), _v| c } .max || 0 end |
#num_rows ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 34 def num_rows reload_cells unless @cells # Memoizes it because this can be bottle-neck. # https://github.com/gimite/google-drive-ruby/pull/49 @num_rows ||= @input_values .reject { |(_r, _c), v| v.empty? } .map { |(r, _c), _v| r } .max || 0 end |
#rows(skip = 0) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 26 def rows(skip = 0) nc = num_cols result = ((1 + skip)..num_rows).map do |row| (1..nc).map { |col| self[row, col] }.freeze end result.freeze end |
#sheet_id ⇒ Object
13 14 15 |
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 13 def sheet_id @properties.sheet_id end |