Module: Roo::Excelx::Format

Extended by:
Format
Included in:
Format
Defined in:
lib/roo/excelx/format.rb

Constant Summary collapse

EXCEPTIONAL_FORMATS =
{
  'h:mm am/pm' => :date,
  'h:mm:ss am/pm' => :date
}
STANDARD_FORMATS =
{
  0 => 'General',
  1 => '0',
  2 => '0.00',
  3 => '#,##0',
  4 => '#,##0.00',
  9 => '0%',
  10 => '0.00%',
  11 => '0.00E+00',
  12 => '# ?/?',
  13 => '# ??/??',
  14 => 'mm-dd-yy',
  15 => 'd-mmm-yy',
  16 => 'd-mmm',
  17 => 'mmm-yy',
  18 => 'h:mm AM/PM',
  19 => 'h:mm:ss AM/PM',
  20 => 'h:mm',
  21 => 'h:mm:ss',
  22 => 'm/d/yy h:mm',
  37 => '#,##0 ;(#,##0)',
  38 => '#,##0 ;[Red](#,##0)',
  39 => '#,##0.00;(#,##0.00)',
  40 => '#,##0.00;[Red](#,##0.00)',
  45 => 'mm:ss',
  46 => '[h]:mm:ss',
  47 => 'mmss.0',
  48 => '##0.0E+0',
  49 => '@'
}

Instance Method Summary collapse

Instance Method Details

#_to_type(format) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/roo/excelx/format.rb', line 48

def _to_type(format)
  format = format.to_s.downcase
  if (type = EXCEPTIONAL_FORMATS[format])
    type
  elsif format.include?('#')
    :float
  elsif format.include?('y') || !format.match(/d+(?![\]])/).nil?
    if format.include?('h') || format.include?('s')
      :datetime
    else
      :date
    end
  elsif format.include?('h') || format.include?('s')
    :time
  elsif format.include?('%')
    :percentage
  else
    :float
  end
end

#to_type(format) ⇒ Object



43
44
45
46
# File 'lib/roo/excelx/format.rb', line 43

def to_type(format)
  @to_type ||= {}
  @to_type[format] ||= _to_type(format)
end