Class: Arbetsformedlingen::MunicipalityCode
- Inherits:
-
Object
- Object
- Arbetsformedlingen::MunicipalityCode
- Defined in:
- lib/arbetsformedlingen/codes/municipality_code.rb
Constant Summary collapse
- CODE_MAP =
CSV.read( File.('../../../data/municipality-codes.csv', __dir__) ).to_h.freeze
- CODES_MAP_INVERTED =
CODE_MAP.invert.freeze
Class Method Summary collapse
- .normalize(name) ⇒ Object
- .to_code(name) ⇒ Object
- .to_form_array(name_only: false) ⇒ Object
- .valid?(name) ⇒ Boolean
Class Method Details
.normalize(name) ⇒ Object
23 24 25 |
# File 'lib/arbetsformedlingen/codes/municipality_code.rb', line 23 def self.normalize(name) name.to_s.strip end |
.to_code(name) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/arbetsformedlingen/codes/municipality_code.rb', line 12 def self.to_code(name) normalized = normalize(name) CODE_MAP.fetch(normalized) do normalized if CODES_MAP_INVERTED[normalized] end end |
.to_form_array(name_only: false) ⇒ Object
27 28 29 30 31 |
# File 'lib/arbetsformedlingen/codes/municipality_code.rb', line 27 def self.to_form_array(name_only: false) return CODE_MAP.to_a unless name_only CODE_MAP.map { |name, _code| [name, name] } end |
.valid?(name) ⇒ Boolean
19 20 21 |
# File 'lib/arbetsformedlingen/codes/municipality_code.rb', line 19 def self.valid?(name) !to_code(name).nil? end |