Class: RODF::Cell
Instance Method Summary collapse
- #add_paragraphs(*elements) ⇒ Object
- #contains_url? ⇒ Boolean
-
#initialize(value = nil, opts = {}) ⇒ Cell
constructor
A new instance of Cell.
- #paragraph(*args, &block) ⇒ Object (also: #p)
- #paragraphs ⇒ Object
- #paragraphs_xml ⇒ Object
- #style=(style_name) ⇒ Object
- #xml ⇒ Object
Methods inherited from Container
Constructor Details
#initialize(value = nil, opts = {}) ⇒ Cell
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rodf/cell.rb', line 4 def initialize(value=nil, opts={}) super if value.is_a?(Hash) opts = value value = opts[: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) ### for auto type inference force :date type because :time doesnt store any date info @type = :date else @type = :string @value = @value.to_s end end end ### TODO: set default DataStyle for the Spreadsheet for Date / Time / DateTime cells formatting @elem_attrs = make_element_attributes(@type, @value, opts) if opts[:attributes] @elem_attrs.merge!(opts[:attributes]) end @multiplier = (opts[:span] || 1).to_i make_value_paragraph end |
Instance Method Details
#add_paragraphs(*elements) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/rodf/cell.rb', line 67 def add_paragraphs(*elements) if elements.first.is_a?(Array) elements = elements.first end elements.each do |element| paragraph(element) end end |
#contains_url? ⇒ Boolean
95 96 97 |
# File 'lib/rodf/cell.rb', line 95 def contains_url? !empty?(@url) end |
#paragraph(*args, &block) ⇒ Object Also known as: p
54 55 56 57 58 59 60 |
# File 'lib/rodf/cell.rb', line 54 def paragraph(*args, &block) x = Paragraph.new(*args, &block) paragraphs << x return x end |
#paragraphs ⇒ Object
50 51 52 |
# File 'lib/rodf/cell.rb', line 50 def paragraphs @paragraphs ||= [] end |
#paragraphs_xml ⇒ Object
63 64 65 |
# File 'lib/rodf/cell.rb', line 63 def paragraphs_xml paragraphs.map(&:xml).join end |
#style=(style_name) ⇒ Object
77 78 79 |
# File 'lib/rodf/cell.rb', line 77 def style=(style_name) @elem_attrs['table:style-name'] = style_name end |
#xml ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rodf/cell.rb', line 81 def xml markup = Builder::XmlMarkup.new text = markup.tag! 'table:table-cell', @elem_attrs do |xml| xml << paragraphs_xml end (@multiplier - 1).times do text = markup.tag! 'table:table-cell' end text end |