Class: RODF::Cell

Inherits:
Container show all
Defined in:
lib/rodf/cell.rb

Instance Method Summary collapse

Methods inherited from Container

contains, create

Constructor Details

#initialize(value = nil, opts = {}) ⇒ Cell

Returns a new instance of Cell.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/rodf/cell.rb', line 29

def initialize(value=nil, opts={})
  if value.is_a?(Hash)
    opts = value
    value = ''
  else
    if value.is_a?(String)
      value = value.strip
    end
    opts = {} unless opts.is_a?(Hash)
  end

  @value = value || ''
  @type = opts[:type]

  unless empty?(@value)
    @url = opts[:url]

    if !@type
      if value.is_a?(Numeric)
        @type = :float
      elsif @value.respond_to?(:strftime)
        @type = :date
        @value = value.to_s

        #if value.is_a?(Date)
        #  @value = value.strftime("%Y-%m-%d")
        #else
        #  @value = value.strftime("%Y%m%dT%H%M%S")
        #end
      else
        @type = :string
        @value = value.to_s
      end
    end
  end

  @elem_attrs = make_element_attributes(@type, @value, opts)
  @multiplier = (opts[:span] || 1).to_i

  make_value_paragraph
end

Instance Method Details

#contains_url?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/rodf/cell.rb', line 84

def contains_url?
  !empty?(@url)
end

#style=(style_name) ⇒ Object



71
72
73
# File 'lib/rodf/cell.rb', line 71

def style=(style_name)
  @elem_attrs['table:style-name'] = style_name
end

#xmlObject



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

def xml
  markup = Builder::XmlMarkup.new
  text = markup.tag! 'table:table-cell', @elem_attrs do |xml|
    xml << paragraphs_xml
  end
  (@multiplier - 1).times {text = markup.tag! 'table:table-cell'}
  text
end