Class: Sheety::Worksheet
Constant Summary collapse
- LINK_ROWS =
'http://schemas.google.com/spreadsheets/2006#listfeed'
- LINK_CELLS =
'http://schemas.google.com/spreadsheets/2006#cellsfeed'
- LINK_VIZ =
'http://schemas.google.com/visualization/2008#visualizationApi'
- LINK_CSV =
'http://schemas.google.com/spreadsheets/2006#exportcsv'
- NATIVE_LINKS =
[LINK_ROWS, LINK_CELLS, LINK_VIZ, LINK_CSV, LINK_SELF, LINK_EDIT]
- LINK_POST =
TODO: Put these in a ListFeed Object, because that’s where they come from
'http://schemas.google.com/g/2005#post'
- LINK_FEED =
'http://schemas.google.com/g/2005#feed'
Constants inherited from Feed
Feed::LINK_ALT, Feed::LINK_EDIT, Feed::LINK_SELF
Instance Attribute Summary collapse
-
#col_count ⇒ Object
Returns the value of attribute col_count.
-
#row_count ⇒ Object
Returns the value of attribute row_count.
Attributes inherited from Feed
#content, #id, #parent, #title, #updated
Instance Method Summary collapse
-
#as_xml ⇒ Object
Serialization Methods.
- #inspect ⇒ Object
- #parse(entry) ⇒ Object
- #to_s ⇒ Object
- #update_rows(data, key_key = 'key', value_key = 'value') ⇒ Object
Methods inherited from Feed
Methods included from Children
#_get_i_val, #_passes_constraint, included
Constructor Details
This class inherits a constructor from Sheety::Feed
Instance Attribute Details
#col_count ⇒ Object
Returns the value of attribute col_count.
15 16 17 |
# File 'lib/sheety/worksheet.rb', line 15 def col_count @col_count end |
#row_count ⇒ Object
Returns the value of attribute row_count.
15 16 17 |
# File 'lib/sheety/worksheet.rb', line 15 def row_count @row_count end |
Instance Method Details
#as_xml ⇒ Object
Serialization Methods
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sheety/worksheet.rb', line 68 def as_xml return [ '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gs="http://schemas.google.com/spreadsheets/2006">', if @id then "<id>#{@id}</id>" else '' end, "<category scheme=\"http://schemas.google.com/spreadsheets/2006\" term=\"http://schemas.google.com/spreadsheets/2006#worksheet\"/>", "<title type=\"text\">#{title}</title>", if link(LINK_EDIT) then "<link rel=\"#{LINK_EDIT}\" type=\"application/atom+xml\" href=\"#{link(LINK_EDIT)}\"/>" else '' end, "<gs:rowCount>#{row_count}</gs:rowCount>", "<gs:colCount>#{col_count}</gs:colCount>", "</entry>", ].join(Sheety::NEWLINE) end |
#inspect ⇒ Object
93 94 95 |
# File 'lib/sheety/worksheet.rb', line 93 def inspect to_s end |
#parse(entry) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/sheety/worksheet.rb', line 20 def parse(entry) super(entry) @col_count = Sheety::Feed.deref(entry, 'gs:colCount', 0).to_i @row_count = Sheety::Feed.deref(entry, 'gs:rowCount', 0).to_i end |
#to_s ⇒ Object
89 90 91 |
# File 'lib/sheety/worksheet.rb', line 89 def to_s "<Worksheet::#{object_id} '#{title}' (#{col_count} x #{row_count}) w/ #{Sheety.length_s(@rows)} Rows & #{Sheety.length_s(@cells)} Cells>" end |
#update_rows(data, key_key = 'key', value_key = 'value') ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sheety/worksheet.rb', line 27 def update_rows(data, key_key='key', value_key='value') logs = {} row_key_key = Sheety::Row.normalize_key(key_key) row_value_key = Sheety::Row.normalize_key(value_key) data.each do |kv| case kv when Array key = kv[0].to_s val = kv[1] when Hash key = kv[key_key].to_s val = kv else raise ArgumentError("Unknown argument type: #{kv.class}") end row = find_row(row_key_key => key) if row.nil? row = new_row row[row_key_key] = key end if Hash === val row.put val else row[row_value_key] = val end resp = row.save unless resp.try(:[], 'id') logs[key] = (resp || "save result was nil") end end return logs end |