lib/xlsx_writer/cell.rb in xlsx_writer-0.1.1 vs lib/xlsx_writer/cell.rb in xlsx_writer-0.1.2
- old
+ new
@@ -6,32 +6,34 @@
# TODO make a class for this
def excel_type(calculated_type)
case calculated_type
when :String
:inlineStr
- when :Number, :Date, :Currency
+ when :Number, :Integer, :Decimal, :Date, :Currency
:n
when :Boolean
:b
else
- raise ::ArgumentError, "Unknown cell type #{k}"
+ raise ::ArgumentError, "Unknown cell type #{calculated_type}"
end
end
# TODO make a class for this
def excel_style_number(calculated_type)
case calculated_type
when :String
0
- when :Number
- 3
+ when :Boolean
+ 0 # todo
when :Currency
1
when :Date
2
- when :Boolean
- 0 # todo
+ when :Number, :Integer
+ 3
+ when :Decimal
+ 4
else
raise ::ArgumentError, "Unknown cell type #{k}"
end
end
@@ -56,10 +58,12 @@
end
str.fast_xs
end
alias :excel_currency :excel_number
+ alias :excel_integer :excel_number
+ alias :excel_decimal :excel_number
# doesn't necessarily work for times yet
JAN_1_1900 = ::Time.parse('1900-01-01')
def excel_date(value)
if value.is_a?(::String)
@@ -99,13 +103,14 @@
BOOLEAN_LENGTH = 'FALSE'.length
def character_width
@character_width ||= case calculated_type
when :String
value.to_s.length
- when :Number
+ when :Number, :Integer, :Decimal
# -1000000.5
len = value.round(2).to_s.length
+ len += 2 if calculated_type == :Decimal
len += 1 if value < 0
len
when :Currency
# (1,000,000.50)
len = value.round(2).to_s.length + ::Math.log(value.abs, 1_000).floor
@@ -153,9 +158,13 @@
def calculated_type
@calculated_type ||= if styled?
data[:type]
elsif value.is_a?(::Date)
:Date
+ elsif value.is_a?(::Integer)
+ :Integer
+ elsif value.is_a?(::Float) or (defined?(::BigDecimal) and value.is_a?(::BigDecimal)) or (defined?(::Decimal) and value.is_a?(::Decimal))
+ :Decimal
elsif value.is_a?(::Numeric)
:Number
else
:String
end