summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorrandym <[email protected]>2018-02-08 21:56:12 +0900
committerrandym <[email protected]>2018-02-08 21:56:12 +0900
commit71dba5a4154edf4939c9537901cbf9217a896515 (patch)
treeb3693a4aac8ef1703ea2f593a03e9c735d764ded /lib
parent747ff93269c518db21c9869b61b1d1470395b502 (diff)
downloadcaxlsx-71dba5a4154edf4939c9537901cbf9217a896515.tar.gz
caxlsx-71dba5a4154edf4939c9537901cbf9217a896515.zip
chore(coverage): 100% coverage, 100% docs
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/rich_text_run.rb6
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/axlsx/workbook/worksheet/rich_text.rb b/lib/axlsx/workbook/worksheet/rich_text.rb
index e8c58c67..81af32b2 100644
--- a/lib/axlsx/workbook/worksheet/rich_text.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text.rb
@@ -1,34 +1,52 @@
module Axlsx
+ # A simple, self serializing class for storing TextRuns
class RichText < SimpleTypedList
+ # creates a new RichText collection
+ # @param [String] text -optional The text to use in creating the first RichTextRun
+ # @param [Object] options -optional The options to use in creating the first RichTextRun
+ # @yield [RichText] self
def initialize(text = nil, options={})
super(RichTextRun)
add_run(text, options) unless text.nil?
yield self if block_given?
end
+ # The cell that owns this RichText collection
attr_reader :cell
+ # Assign the cell for this RichText collection
+ # @param [Cell] cell The cell which all RichTextRuns in the collection will belong to
def cell=(cell)
@cell = cell
each { |run| run.cell = cell }
end
+ # Calculates the longest autowidth of the RichTextRuns in this collection
+ # @return [Number]
def autowidth
widtharray = [0] # Are arrays the best way of solving this problem?
each { |run| run.autowidth(widtharray) }
widtharray.max
end
+ # Creates and adds a RichTextRun to this collectino
+ # @param [String] text The text to use in creating a new RichTextRun
+ # @param [Object] options The options to use in creating the new RichTextRun
def add_run(text, options={})
self << RichTextRun.new(text, options)
end
+ # The RichTextRuns we own
+ # @return [RichText]
def runs
self
end
+ # renders the RichTextRuns in this collection
+ # @param [String] str
+ # @return [String]
def to_xml_string(str='')
each{ |run| run.to_xml_string(str) }
str
diff --git a/lib/axlsx/workbook/worksheet/rich_text_run.rb b/lib/axlsx/workbook/worksheet/rich_text_run.rb
index e709f265..40d99bb0 100644
--- a/lib/axlsx/workbook/worksheet/rich_text_run.rb
+++ b/lib/axlsx/workbook/worksheet/rich_text_run.rb
@@ -1,10 +1,13 @@
module Axlsx
+
+ # The RichTextRun class creates and self serializing text run.
class RichTextRun
include Axlsx::OptionsParser
attr_reader :value
+ # A list of allowed inline style attributes used for validation
INLINE_STYLES = [:font_name, :charset,
:family, :b, :i, :strike, :outline,
:shadow, :condense, :extend, :u,
@@ -182,6 +185,9 @@ module Axlsx
self.instance_variable_set :"@#{attr.to_s}", value
end
+ # Serializes the RichTextRun
+ # @param [String] str
+ # @return [String]
def to_xml_string(str = '')
valid = RichTextRun::INLINE_STYLES
data = Hash[self.instance_values.map{ |k, v| [k.to_sym, v] }]