Class: Ods::Cell

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, row) ⇒ Cell



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

def initialize(content, row)
  @content = content
  @row = row
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/ods/cell.rb', line 3

def content
  @content
end

#rowObject (readonly)

Returns the value of attribute row.



3
4
5
# File 'lib/ods/cell.rb', line 3

def row
  @row
end

Instance Method Details

#textObject



34
35
36
# File 'lib/ods/cell.rb', line 34

def text
  content.text
end

#valueObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ods/cell.rb', line 10

def value
  value_type = content['office:value-type']
  #puts "value_type=#{value_type}"
  case value_type
    when nil, 'string'
      text
    when 'date'
      Date.strptime(content['office:date-value'], "%Y-%m-%d")
    when 'boolean'
      content['office:boolean-value'] == 'true' ? true : false
    when 'float'
      str = content['office:value']
      if str.match(/\./)
        str.to_f
      else
        str.to_i
      end
    when 'percentage'
      content['office:value'].to_f
    else
      warn "Unknown type: #{value_type} [#{text}]"
  end
end