Class: CountryConvert
- Inherits:
-
Object
- Object
- CountryConvert
- Defined in:
- lib/countryconvert.rb
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(input, countryfield) ⇒ CountryConvert
constructor
A new instance of CountryConvert.
Constructor Details
#initialize(input, countryfield) ⇒ CountryConvert
Returns a new instance of CountryConvert.
4 5 6 7 8 |
# File 'lib/countryconvert.rb', line 4 def initialize(input, countryfield) @input = JSON.parse(input) @countryfield = countryfield @isocodes = JSON.parse(File.read("isocodes.json")) end |
Instance Method Details
#convert ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/countryconvert.rb', line 10 def convert finaldata = Array.new @input.each do |f| if @isocodes[f[@countryfield].upcase] threeletter = @isocodes[f[@countryfield].upcase] f[@countryfield] = threeletter finaldata.push(f) end end return JSON.pretty_generate(finaldata) end |