Class: Worldwide::Fields

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/worldwide/fields.rb

Instance Method Summary collapse

Constructor Details

#initializeFields

Returns a new instance of Fields.



18
19
20
# File 'lib/worldwide/fields.rb', line 18

def initialize
  @fields = {}
end

Instance Method Details

#field(country_code:, field_key:) ⇒ Object

Return a Worldwide::Field for the specified country_code and field_key



23
24
25
26
27
28
29
30
31
32
# File 'lib/worldwide/fields.rb', line 23

def field(country_code:, field_key:)
  code = country_code.upcase.to_sym
  key = field_key.downcase.to_sym

  cache_key = "#{code}|#{key}".to_sym
  cached = @fields[cache_key]
  return cached if cached

  @fields[cache_key] = Field.new(country_code: code, field_key: key)
end