Class: ODF::Cell

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Cell

Returns a new instance of Cell.



23
24
25
26
27
28
29
30
31
# File 'lib/odf/cell.rb', line 23

def initialize(*args)
  value = args.first || ''
  opts = args.last.instance_of?(Hash) ? args.last : {}

  @type = opts[:type] || :string
  @value = value.to_s.strip unless value.instance_of? Hash

  @elem_attrs = make_element_attributes(@type, @value, opts)
end

Instance Method Details

#contains_string?Boolean

Returns:

  • (Boolean)


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

def contains_string?
  :string == @type && !@value.nil? && !@value.empty?
end

#make_element_attributes(type, value, opts) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/odf/cell.rb', line 43

def make_element_attributes(type, value, opts)
  attrs = {'office:value-type' => type}
  attrs['office:value'] = value unless contains_string?
  attrs['table:formula'] = opts[:formula] unless opts[:formula].nil?
  attrs['table:style-name'] = opts[:style] unless opts[:style].nil?
  attrs['table:number-matrix-columns-spanned'] =
    attrs['table:number-matrix-rows-spanned'] = 1 if opts[:matrix_formula]
  attrs
end

#xmlObject



33
34
35
36
37
# File 'lib/odf/cell.rb', line 33

def xml
  Builder::XmlMarkup.new.tag! 'table:table-cell', @elem_attrs do |xml|
    xml.text(:p, @value) if contains_string?
  end
end