Class: ReadXls::Type::ExtendedFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/read_xls/type/extended_format.rb

Constant Summary collapse

FORMAT_MATCHERS =
{
  /[YMDymd]/ => :date
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ExtendedFormat

Returns a new instance of ExtendedFormat.



10
11
12
# File 'lib/read_xls/type/extended_format.rb', line 10

def initialize(options)
  self.format_string = options.fetch(:format_string)
end

Instance Attribute Details

#format_stringObject

Returns the value of attribute format_string.



4
5
6
# File 'lib/read_xls/type/extended_format.rb', line 4

def format_string
  @format_string
end

Instance Method Details

#format_typeObject



14
15
16
17
18
19
20
21
22
# File 'lib/read_xls/type/extended_format.rb', line 14

def format_type
  matched_types = FORMAT_MATCHERS.select { |matcher, _| format_string =~ matcher }

  if matched_types.length > 1
    raise "got more than one match, expected only one matched format type"
  end

  matched_types.values.first
end