Class: Validiso::Data
- Inherits:
-
Object
- Object
- Validiso::Data
- Defined in:
- lib/validiso/data.rb
Class Method Summary collapse
- .alpha2 ⇒ Object
- .alpha3 ⇒ Object
- .bucket_collector(key) ⇒ Object
- .codes ⇒ Object
- .json ⇒ Object
- .read_data_file ⇒ Object
Class Method Details
.alpha2 ⇒ Object
19 20 21 |
# File 'lib/validiso/data.rb', line 19 def alpha2 @@alpha2||= bucket_collector('alpha2') end |
.alpha3 ⇒ Object
23 24 25 |
# File 'lib/validiso/data.rb', line 23 def alpha3 @@alpha3||= bucket_collector('alpha3') end |
.bucket_collector(key) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/validiso/data.rb', line 27 def bucket_collector(key) bucket = {} json.each do |obj| bucket[obj[key]] = obj end bucket end |
.codes ⇒ Object
15 16 17 |
# File 'lib/validiso/data.rb', line 15 def codes @@codes||= bucket_collector('country_code') end |
.json ⇒ Object
6 7 8 |
# File 'lib/validiso/data.rb', line 6 def json @@json ||= JSON.parse(read_data_file) end |
.read_data_file ⇒ Object
10 11 12 13 |
# File 'lib/validiso/data.rb', line 10 def read_data_file file_path = File.('../data/countries.json', __FILE__) File.read(file_path) end |