Class: Xlsxtream::Row
- Inherits:
-
Object
- Object
- Xlsxtream::Row
- Defined in:
- lib/xlsxtream/row.rb
Constant Summary collapse
- ENCODING =
Encoding.find('UTF-8')
- NUMBER_PATTERN =
/\A-?[0-9]+(\.[0-9]+)?\z/.freeze
- DATE_PATTERN =
ISO 8601 yyyy-mm-dd
/\A[0-9]{4}-[0-9]{2}-[0-9]{2}\z/.freeze
- TIME_PATTERN =
ISO 8601 yyyy-mm-ddThh:mm:ss(.s)(Z|+hh:mm|-hh:mm)
/\A[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}(?::[0-9]{2}(?:\.[0-9]{1,9})?)?(?:Z|[+-][0-9]{2}:[0-9]{2})?\z/.freeze
- DATE_STYLE =
1- TIME_STYLE =
2
Instance Method Summary collapse
-
#initialize(row, rownum, options = {}) ⇒ Row
constructor
A new instance of Row.
- #to_xml ⇒ Object
Constructor Details
#initialize(row, rownum, options = {}) ⇒ Row
Returns a new instance of Row.
19 20 21 22 23 24 |
# File 'lib/xlsxtream/row.rb', line 19 def initialize(row, rownum, = {}) @row = row @rownum = rownum @sst = [:sst] @auto_format = [:auto_format] end |
Instance Method Details
#to_xml ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/xlsxtream/row.rb', line 26 def to_xml column = 'A' xml = %Q{<row r="#{@rownum}">} @row.each do |value| cid = "#{column}#{@rownum}" column.next! if @auto_format && value.is_a?(String) value = auto_format(value) end case value when Numeric xml << %Q{<c r="#{cid}" t="n"><v>#{value}</v></c>} when Time, DateTime xml << %Q{<c r="#{cid}" s="#{TIME_STYLE}"><v>#{time_to_oa_date(value)}</v></c>} when Date xml << %Q{<c r="#{cid}" s="#{DATE_STYLE}"><v>#{time_to_oa_date(value)}</v></c>} else value = value.to_s unless value.empty? # no xml output for for empty strings value = value.encode(ENCODING) if value.encoding != ENCODING if @sst xml << %Q{<c r="#{cid}" t="s"><v>#{@sst[value]}</v></c>} else xml << %Q{<c r="#{cid}" t="inlineStr"><is><t>#{XML.escape_value(value)}</t></is></c>} end end end end xml << '</row>' end |