Module: Fortnox::Mappers::CountryCode
- Defined in:
- lib/fortnox/mappers/country_code.rb
Class Method Summary collapse
-
.parse(country) ⇒ Object
Blank maps to nil in both directions, mirroring the string types: Fortnox spells "unset" country as "" on reads, and on updates only an explicit null clears the field — "" is silently ignored.
- .serialise(country_code) ⇒ Object
Class Method Details
.parse(country) ⇒ Object
Blank maps to nil in both directions, mirroring the string types: Fortnox spells "unset" country as "" on reads, and on updates only an explicit null clears the field — "" is silently ignored.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fortnox/mappers/country_code.rb', line 13 def self.parse(country) return nil if country.nil? || country == '' # Fortnox only supports Swedish translation of Sweden return 'SE' if country =~ /^s(e$|we|ve)/i country = ::ISO3166::Country[country] || ::ISO3166::Country.find_country_by_iso_short_name(country) || ::ISO3166::Country.find_country_by_translated_names(country) raise Fortnox::AttributeError, '"Country" violates constraints' if country.nil? country.alpha2 end |
.serialise(country_code) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/fortnox/mappers/country_code.rb', line 28 def self.serialise(country_code) return nil if country_code.nil? || country_code == '' return 'Sverige' if country_code == 'SE' ::ISO3166::Country.new(country_code).translations['en'] end |