summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/rich_text.rb
blob: 18c8e6b54602984c0ff53fb24224acff9e6e4ad1 (plain)
1
2
3
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
module Axlsx
  class RichText
    def initialize(text = nil, options={})
       @runs = SimpleTypedList.new(RichTextRun)
       add_run(text, options) unless text.nil?
       yield self if block_given?
    end

    attr_reader :runs
    
    attr_reader :cell
    
    def cell=(cell)
      @cell = cell
      @runs.each { |run| run.cell = cell }
    end
    
    def autowidth
      widtharray = [0] # Are arrays the best way of solving this problem?
      @runs.each { |run| run.autowidth(widtharray) }
      widtharray.max
    end

    def add_run(text, options={})
      @runs << RichTextRun.new(text, options)
    end

    def to_xml_string(str='')
      runs.each{ |run| run.to_xml_string(str) }
      str
    end
  end
end