Class: Paperize::Worksheet
- Inherits:
-
Object
- Object
- Paperize::Worksheet
- Defined in:
- lib/paperize/worksheet.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(option = nil) ⇒ Object
- #cards ⇒ Object
-
#initialize(title, labels, rows) ⇒ Worksheet
constructor
A new instance of Worksheet.
Constructor Details
#initialize(title, labels, rows) ⇒ Worksheet
Returns a new instance of Worksheet.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/paperize/worksheet.rb', line 11 def initialize(title, labels, rows) raise_on_duplicates(labels) @title = title @labels = labels @attributes = @labels.map do |label| unless label.nil? label.downcase.gsub(' ', '_').gsub('/', '_').to_sym end end @rows = rows.map do |row| card = OpenStruct.new @attributes.zip(row).each do |attribute_value_pair| attribute = attribute_value_pair[0] unless attribute.nil? or attribute.empty? card.send("#{attribute}=".to_sym, attribute_value_pair[1]) end end card end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/paperize/worksheet.rb', line 10 def attributes @attributes end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
10 11 12 |
# File 'lib/paperize/worksheet.rb', line 10 def labels @labels end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
10 11 12 |
# File 'lib/paperize/worksheet.rb', line 10 def rows @rows end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
10 11 12 |
# File 'lib/paperize/worksheet.rb', line 10 def title @title end |
Class Method Details
.find(options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/paperize/worksheet.rb', line 5 def self.find(={}) spreadsheet = Paperize::Spreadsheet.find([:spreadsheet_key]) spreadsheet.worksheet_by_title([:worksheet_title]) end |
Instance Method Details
#as_json(option = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/paperize/worksheet.rb', line 40 def as_json(option=nil) { title: @title, columns: @labels } end |
#cards ⇒ Object
36 37 38 |
# File 'lib/paperize/worksheet.rb', line 36 def cards rows end |