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
-
.boolean_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type boolean.
-
.date_type_serialization(cell, str = '') ⇒ String
serializes cells that are type date.
-
.float_type_serialization(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_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type integer.
-
.iso_8601_type_serialization(cell, str = '') ⇒ String
serializes cells that are type iso_8601.
-
.run_xml_string(cell, str = '') ⇒ String
builds an xml text run based on this cells attributes.
-
.string_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type string.
-
.time_type_serialization(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
.boolean_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type boolean
76 77 78 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 76 def boolean_type_serialization(cell, str='') value_serialization 'b', cell.value.to_s, str end |
.date_type_serialization(cell, str = '') ⇒ String
serializes cells that are type date
60 61 62 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 60 def date_type_serialization(cell, str='') value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str end |
.float_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type float
84 85 86 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 84 def float_type_serialization(cell, str='') numeric_type_serialization cell, str end |
.formula_serialization(cell, str = '') ⇒ String
Serializes cells that are type formula
101 102 103 104 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 101 def formula_serialization(cell, str='') str << 't="str">' << '<f>' << cell.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
110 111 112 113 114 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 110 def inline_string_serialization(cell, str = '') str << 't="inlineStr">' << '<is>' run_xml_string cell, str str << '</is>' end |
.integer_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type integer
92 93 94 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 92 def integer_type_serialization(cell, str = '') numeric_type_serialization cell, str end |
.iso_8601_type_serialization(cell, str = '') ⇒ String
serializes cells that are type iso_8601
51 52 53 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 51 def iso_8601_type_serialization(cell, str='') value_serialization 'd', cell.value, str end |
.run_xml_string(cell, str = '') ⇒ String
builds an xml text run based on this cells attributes.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 25 def run_xml_string(cell, str = '') if cell.is_text_run? data = cell.instance_values.reject{|key, value| value == nil || key == 'value' || key == 'type' } keys = data.keys & Cell::INLINE_STYLES str << "<r><rPr>" keys.each do |key| case key when 'font_name' str << "<rFont val='"<< cell.font_name << "'/>" when 'color' str << data[key].to_xml_string else str << "<" << key.to_s << " val='" << data[key].to_s << "'/>" end end str << "</rPr>" << "<t>" << cell.value.to_s << "</t></r>" else str << "<t>" << cell.value.to_s << "</t>" end str end |
.string_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type string
120 121 122 123 124 125 126 127 128 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 120 def string_type_serialization(cell, str='') if cell.is_formula? formula_serialization cell, str elsif !cell.ssti.nil? value_serialization 's', cell.ssti.to_s, str else inline_string_serialization cell, str end end |
.time_type_serialization(cell, str = '') ⇒ String
Serializes cells that are type time
68 69 70 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 68 def time_type_serialization(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.
13 14 15 16 17 18 19 |
# File 'lib/axlsx/workbook/worksheet/cell_serializer.rb', line 13 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.to_s << '_type_serialization').to_sym self.send(method, cell, str) str << '</c>' end |