class Sheety::Worksheet

Constants

LINK_POST

TODO: Put these in a ListFeed Object, because that's where they come from

Attributes

col_count[RW]
row_count[RW]

Public Instance Methods

as_xml() click to toggle source

Serialization Methods

# 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() click to toggle source
# File lib/sheety/worksheet.rb, line 93
def inspect
  to_s
end
parse(entry) click to toggle source
Calls superclass method Sheety::Feed#parse
# 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() click to toggle source
# 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') click to toggle source
# 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