Class: Translator::LanguageBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/natural-date/language_bundle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lang) ⇒ LanguageBundle

Returns a new instance of LanguageBundle.



7
8
9
10
11
12
13
14
15
16
# File 'lib/natural-date/language_bundle.rb', line 7

def initialize lang
  @lang = lang.freeze

  @types_range = { week_day: 0..6, month: 1..12 }.freeze
  @types_map = load_types_map.freeze
  @values = load_values.freeze
  @months = load_months.freeze
  @values_map = @values.map { |key, value| value.split(' ').map { |v| { v => key } } }.flatten.reduce({}) { |e, map| map.merge(e) }.freeze
  @separator_regexp = Regexp.new(@types_map.select { |_k, v| v == :separator }.keys.map { |k| " #{k} " }.join '|').freeze
end

Instance Attribute Details

#monthsObject (readonly)

Returns the value of attribute months.



5
6
7
# File 'lib/natural-date/language_bundle.rb', line 5

def months
  @months
end

#separator_regexpObject (readonly)

Returns the value of attribute separator_regexp.



5
6
7
# File 'lib/natural-date/language_bundle.rb', line 5

def separator_regexp
  @separator_regexp
end

#types_mapObject (readonly)

Returns the value of attribute types_map.



5
6
7
# File 'lib/natural-date/language_bundle.rb', line 5

def types_map
  @types_map
end

#types_rangeObject (readonly)

Returns the value of attribute types_range.



5
6
7
# File 'lib/natural-date/language_bundle.rb', line 5

def types_range
  @types_range
end

#valuesObject (readonly)

Returns the value of attribute values.



5
6
7
# File 'lib/natural-date/language_bundle.rb', line 5

def values
  @values
end

#values_mapObject (readonly)

Returns the value of attribute values_map.



5
6
7
# File 'lib/natural-date/language_bundle.rb', line 5

def values_map
  @values_map
end

Class Method Details

.fetch(lang) ⇒ Object



18
19
20
# File 'lib/natural-date/language_bundle.rb', line 18

def self.fetch lang
  BUNDLES[lang] ||= LanguageBundle.new(lang)
end