Class: TurkeyRegions
- Inherits:
-
Object
- Object
- TurkeyRegions
- Defined in:
- lib/turkey_regions.rb
Class Method Summary collapse
Class Method Details
.cities_by_region(region, options = { include_city_name: false }) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/turkey_regions.rb', line 12 def self.cities_by_region(region, = { include_city_name: false }) begin source = YAML.load_file(File.join(File.dirname(__FILE__), 'data', 'regions_and_cities.yaml')) matched_region = source.select { |r| r == region } if [:include_city_name] matched_region[region]['subdivisions'] else matched_region[region]['subdivisions'].map { |s| s['code'] } end rescue raise StandardError.new('given region could not be found') end end |
.regions ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/turkey_regions.rb', line 2 def self.regions items = [] source = YAML.load_file(File.join(File.dirname(__FILE__), 'data', 'regions_and_cities.yaml')) source.each do |region| items << { id: region[0], name: region[1]['translations'][I18n.locale.to_s.split('-')[0]] } end items end |