class Sheety::Row

Public Class Methods

new(parent, entry=nil) click to toggle source
Calls superclass method Sheety::Feed::new
# File lib/sheety/row.rb, line 4
def initialize(parent, entry=nil)
  @attrs = {}
  super(parent, entry)
end
normalize_key(key) click to toggle source
# File lib/sheety/row.rb, line 84
def self.normalize_key(key)
  key.to_s.gsub(/[^a-zA-Z0-9]/, '')
end

Public Instance Methods

[](key)
Alias for: value
[]=(key, val) click to toggle source
# File lib/sheety/row.rb, line 24
def []=(key, val)
  @attrs['gsx:' + key.to_s]=val
end
as_xml() click to toggle source
# File lib/sheety/row.rb, line 32
def as_xml
  return [
      '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">',
      if !@id then
        ''
      else
        "<id>#{@id}</id>"
      end,
      if !@id then
        ''
      else
        "<updated>#{DateTime.now}</updated>"
      end,
      if !@id then
        ''
      else
        '<category scheme="http://schemas.google.com/spreadsheets/2006" term="http://schemas.google.com/spreadsheets/2006#list"/>'
      end,
      if !@id then
        ''
      else
        "<link rel=\"edit\" type=\"application/atom+xml\" href=\"#{@links[LINK_EDIT]}\" />"
      end,
      *(@attrs.map { |pair| "<#{pair[0]}>#{pair[1]}</#{pair[0]}>" }),
      '</entry>',
  ].join(Sheety::NEWLINE)
end
delete() click to toggle source

ProTip: Delete Rows in Reverse, otherwise the shift of deletion will cause unexpected behaviors

# File lib/sheety/row.rb, line 72
def delete
  return Sheety::Api.inst.delete_feed(link(LINK_EDIT))
end
inspect() click to toggle source
# File lib/sheety/row.rb, line 80
def inspect
  to_s
end
parse(entry) click to toggle source
Calls superclass method Sheety::Feed#parse
# File lib/sheety/row.rb, line 9
def parse(entry)
  super(entry)
  entry.keys.each do |k|
    if /\Agsx:/i =~ k
      @attrs[k] = entry[k][0]
    end
  end
end
put(hash) click to toggle source
# File lib/sheety/row.rb, line 28
def put(hash)
  hash.each { |kv| self[Sheety::Row.normalize_key(kv[0])] = kv[1] }
end
save() click to toggle source
# File lib/sheety/row.rb, line 60
def save
  uri = link(LINK_EDIT)
  if uri
    return Sheety::Api.inst.put_feed(uri, as_xml)
  else
    return Sheety::Api.inst.post_feed(@parent.link(Sheety::Worksheet::LINK_POST), as_xml)
  end
end
Also aliased as: update
to_s() click to toggle source
# File lib/sheety/row.rb, line 76
def to_s
  "<#{self.class}::#{object_id} #{(@attrs.map { |kv| "#{kv[0].gsub('gsx:', '')}:#{kv[1]}" }).join(', ')}>"
end
update()
Alias for: save
value(key) click to toggle source
# File lib/sheety/row.rb, line 18
def value(key)
  return @attrs['gsx:' + key.to_s]
end
Also aliased as: []