Class: Worldwide::Fields
- Inherits:
-
Object
- Object
- Worldwide::Fields
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/worldwide/fields.rb
Instance Method Summary collapse
-
#field(country_code:, field_key:) ⇒ Object
Return a Worldwide::Field for the specified country_code and field_key.
-
#initialize ⇒ Fields
constructor
A new instance of Fields.
Constructor Details
#initialize ⇒ Fields
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 |