Class: Axlsx::RichText

Inherits:
SimpleTypedList
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/rich_text.rb

Overview

A simple, self serializing class for storing TextRuns

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = nil, options = {}) {|RichText| ... } ⇒ RichText

creates a new RichText collection

Parameters:

  • text (String) (defaults to: nil)

    -optional The text to use in creating the first RichTextRun

  • options (Object) (defaults to: {})

    -optional The options to use in creating the first RichTextRun

Yields:



10
11
12
13
14
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 10

def initialize(text = nil, options={})
  super(RichTextRun)
  add_run(text, options) unless text.nil?
  yield self if block_given?
end

Instance Attribute Details

#cellObject

The cell that owns this RichText collection



17
18
19
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 17

def cell
  @cell
end

Instance Method Details

#add_run(text, options = {}) ⇒ Object

Creates and adds a RichTextRun to this collectino

Parameters:

  • text (String)

    The text to use in creating a new RichTextRun

  • options (Object) (defaults to: {})

    The options to use in creating the new RichTextRun



37
38
39
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 37

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

#autowidthNumber

Calculates the longest autowidth of the RichTextRuns in this collection

Returns:

  • (Number)


28
29
30
31
32
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 28

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

#runsRichText

The RichTextRuns we own

Returns:



43
44
45
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 43

def runs
  self
end

#to_xml_string(str = '') ⇒ String

renders the RichTextRuns in this collection

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


50
51
52
53
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 50

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