Class: Axlsx::CellSerializer
- Inherits:
-
Object
- Object
- Axlsx::CellSerializer
- Defined in:
- lib/axlsx/workbook/worksheet/cell_serializer.rb
Overview
The Cell Serializer class contains the logic for serializing cells based on their type.
Class Method Summary collapse
-
.array_formula_serialization(cell, str = '') ⇒ String
Serializes cells that are type array formula.
-
.boolean(cell, str = '') ⇒ String
Serializes cells that are type boolean.
-
.date(cell, str = '') ⇒ String
serializes cells that are type date.
-
.float(cell, str = '') ⇒ String
Serializes cells that are type float.
-
.formula_serialization(cell, str = '') ⇒ String
Serializes cells that are type formula.
-
.inline_string_serialization(cell, str = '') ⇒ String
Serializes cells that are type inline_string.
-
.integer(cell, str = '') ⇒ String
Serializes cells that are type integer.
-
.iso_8601(cell, str = '') ⇒ String
serializes cells that are type iso_8601.
-
.richtext(cell, str) ⇒ String
Serializes cells that are of the type richtext.
-
.run_xml_string(cell, str = '') ⇒ String
builds an xml text run based on this cells attributes.
-
.string(cell, str = '') ⇒ String
Serializes cells that are type string.
-
.time(cell, str = '') ⇒ String
Serializes cells that are type time.
-
.to_xml_string(row_index, column_index, cell, str = '') ⇒ String
Calls the proper serialization method based on type.
Class Method Details
.array_formula_serialization(cell, str = '') ⇒ String
Serializes cells that are type array formula
97 98 99 100 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 97 def array_formula_serialization(cell, str='') str << ('t="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.sub('{=', '').sub(/}$/, '') << '</f>') str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil? end |
.boolean(cell, str = '') ⇒ String
Serializes cells that are type boolean
64 65 66 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 64 def boolean(cell, str='') value_serialization 'b', cell.value.to_s, str end |
.date(cell, str = '') ⇒ String
serializes cells that are type date
48 49 50 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 48 def date(cell, str='') value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str end |
.float(cell, str = '') ⇒ String
Serializes cells that are type float
72 73 74 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 72 def float(cell, str='') numeric cell, str end |
.formula_serialization(cell, str = '') ⇒ String
Serializes cells that are type formula
88 89 90 91 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 88 def formula_serialization(cell, str='') str << ('t="str"><f>' << cell.clean_value.to_s.sub('=', '') << '</f>') str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil? end |
.inline_string_serialization(cell, str = '') ⇒ String
Serializes cells that are type inline_string
106 107 108 109 110 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 106 def inline_string_serialization(cell, str = '') str << 't="inlineStr"><is>' run_xml_string cell, str str << '</is>' end |
.integer(cell, str = '') ⇒ String
Serializes cells that are type integer
80 81 82 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 80 def integer(cell, str = '') numeric cell, str end |
.iso_8601(cell, str = '') ⇒ String
serializes cells that are type iso_8601
40 41 42 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 40 def iso_8601(cell, str='') value_serialization 'd', cell.value, str end |
.richtext(cell, str) ⇒ String
Serializes cells that are of the type richtext
132 133 134 135 136 137 138 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 132 def richtext(cell, str) if cell.ssti.nil? inline_string_serialization cell, str else value_serialization 's', cell.ssti, str end end |
.run_xml_string(cell, str = '') ⇒ String
builds an xml text run based on this cells attributes.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 22 def run_xml_string(cell, str = '') if cell.is_text_run? valid = RichTextRun::INLINE_STYLES - [:value, :type] data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }] data = data.select { |key, value| valid.include?(key) && !value.nil? } RichText.new(cell.value.to_s, data).to_xml_string(str) elsif cell.contains_rich_text? cell.value.to_xml_string(str) else str << ('<t>' << cell.clean_value << '</t>') end str end |
.string(cell, str = '') ⇒ String
Serializes cells that are type string
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 116 def string(cell, str='') if cell.is_array_formula? array_formula_serialization cell, str elsif cell.is_formula? formula_serialization cell, str elsif !cell.ssti.nil? value_serialization 's', cell.ssti, str else inline_string_serialization cell, str end end |
.time(cell, str = '') ⇒ String
Serializes cells that are type time
56 57 58 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 56 def time(cell, str='') value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str end |
.to_xml_string(row_index, column_index, cell, str = '') ⇒ String
Calls the proper serialization method based on type.
11 12 13 14 15 16 17 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 11 def to_xml_string(row_index, column_index, cell, str='') str << ('<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" ') return str << '/>' if cell.value.nil? method = cell.type self.send(method, cell, str) str << '</c>' end |