Class: Sheety::Cell

Inherits:
Feed
  • Object
show all
Defined in:
lib/sheety/cell.rb

Constant Summary collapse

COL_LETTERS =
[nil, *('A'..'Z')]

Constants inherited from Feed

Feed::LINK_ALT, Feed::LINK_EDIT, Feed::LINK_SELF

Instance Attribute Summary collapse

Attributes inherited from Feed

#content, #id, #parent, #title, #updated

Instance Method Summary collapse

Methods inherited from Feed

#initialize, #link

Methods included from Children

#_get_i_val, #_passes_constraint, included

Constructor Details

This class inherits a constructor from Sheety::Feed

Instance Attribute Details

#colObject

Returns the value of attribute col.



6
7
8
# File 'lib/sheety/cell.rb', line 6

def col
  @col
end

#display_valueObject (readonly)

Returns the value of attribute display_value.



6
7
8
# File 'lib/sheety/cell.rb', line 6

def display_value
  @display_value
end

#input_valueObject (readonly)

Returns the value of attribute input_value.



6
7
8
# File 'lib/sheety/cell.rb', line 6

def input_value
  @input_value
end

#numeric_valueObject (readonly)

Returns the value of attribute numeric_value.



6
7
8
# File 'lib/sheety/cell.rb', line 6

def numeric_value
  @numeric_value
end

#rowObject

Returns the value of attribute row.



6
7
8
# File 'lib/sheety/cell.rb', line 6

def row
  @row
end

Instance Method Details

#as_batch_xmlObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sheety/cell.rb', line 63

def as_batch_xml
  return [
      "<entry>",
      "<batch:id>#{title}</batch:id>",
      "<batch:operation type=\"update\" />",
      "<id>#{id}</id>",
      "<link rel=\"#{LINK_EDIT}\" type=\"application/atom+xml\"",
      "href=\"#{link(LINK_EDIT)}\"/>",
      "<gs:cell row=\"#{@row}\" col=\"#{@col}\" inputValue=\"#{@input_value}\"/>",
      "</entry>",
  ].join(Sheety::NEWLINE)
end

#as_xmlObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sheety/cell.rb', line 43

def as_xml
  return [
      "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:gs=\"http://schemas.google.com/spreadsheets/2006\">",
      "<id>#{
      if @id then
        @id
      else
        @parent.link(Sheety::Worksheet::LINK_CELLS) + "/#{rc}"
      end}</id>",
      "<link rel=\"#{Sheety::Feed::LINK_EDIT}\" type=\"application/atom+xml\" href=\"#{
      if link(LINK_EDIT) then
        link(LINK_EDIT)
      else
        @parent.link(Sheety::Worksheet::LINK_CELLS) + "/#{rc}"
      end}\"/>",
      "<gs:cell row=\"#{row}\" col=\"#{col}\" inputValue=\"#{input_value}\"/>",
      "</entry>",
  ].join(Sheety::NEWLINE)
end

#inspectObject



89
90
91
# File 'lib/sheety/cell.rb', line 89

def inspect
  to_s
end

#parse(entry) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/sheety/cell.rb', line 8

def parse(entry)
  super(entry)
  cell = entry['gs:cell'][0]

  @row = cell['row'].to_i
  @col = cell['col'].to_i
  @input_value = cell['inputValue']
  @numeric_value = cell['numericValue'].to_f
  @display_value = cell['content']
end

#rcObject



39
40
41
# File 'lib/sheety/cell.rb', line 39

def rc
  return "R#{row}C#{col}"
end

#saveObject



76
77
78
79
80
81
82
83
# File 'lib/sheety/cell.rb', line 76

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_CELLS), as_xml)
  end
end

#to_sObject



85
86
87
# File 'lib/sheety/cell.rb', line 85

def to_s
  "<#{self.class}::#{object_id} #{rc} input='#{input_value}' numeric='#{numeric_value}' display='#{display_value}'>"
end

#value=(new_value) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/sheety/cell.rb', line 19

def value=(new_value)
  if new_value != @input_value
    @input_value = new_value
    @numeric_value = nil
    @display_value = nil
  end
end