Class: Worksheet

Inherits:
Object
  • Object
show all
Defined in:
lib/solis/shape/reader/simple_sheets/worksheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#propertiesObject (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

#spreadsheetObject (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

#titleObject (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

#gidObject



17
18
19
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 17

def gid
  sheet_id.to_s
end

#num_colsObject

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_rowsObject



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_idObject



13
14
15
# File 'lib/solis/shape/reader/simple_sheets/worksheet.rb', line 13

def sheet_id
  @properties.sheet_id
end