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:



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

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



15
16
17
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 15

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



35
36
37
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 35

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

#autowidthNumber

Calculates the longest autowidth of the RichTextRuns in this collection

Returns:

  • (Number)


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

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:



41
42
43
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 41

def runs
  self
end

#to_xml_string(str = '') ⇒ String

renders the RichTextRuns in this collection

Parameters:

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

Returns:

  • (String)


48
49
50
51
# File 'lib/axlsx/workbook/worksheet/rich_text.rb', line 48

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