Class: SwissVillageDirectory::Repository
- Inherits:
-
Object
- Object
- SwissVillageDirectory::Repository
- Defined in:
- lib/swiss_village_directory/repository.rb
Instance Attribute Summary collapse
-
#villages ⇒ Object
readonly
Returns the value of attribute villages.
Instance Method Summary collapse
- #find_all_by(find_params) ⇒ Object
-
#initialize ⇒ Repository
constructor
A new instance of Repository.
Constructor Details
#initialize ⇒ Repository
Returns a new instance of Repository.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/swiss_village_directory/repository.rb', line 8 def initialize filename = File.dirname(__FILE__) + '/../../data/PLZO_CSV_WGS84.csv' = { col_sep: ';', encoding: 'ISO-8859-1:UTF-8', headers: :first_row } source_key_mapping = { 'Ortschaftsname' => :name, 'PLZ' => :zip_code, 'Zusatzziffer' => :one_digit_spare, 'Gemeindename' => :commune, 'BFS-Nr' => :bfs_number, 'Kantonskürzel' => :canton, 'E' => :longitude, 'N' => :latitude, 'Sprache' => :language } villages_hashes = CSV.open(filename, 'r', **).map do |row| row.to_h.transform_keys { |k| source_key_mapping[k] } end @villages = villages_hashes.map do |h| Village.new(h[:name], h[:zip_code], h[:one_digit_spare], h[:commune], h[:canton], h[:longitude], h[:latitude]) end end |
Instance Attribute Details
#villages ⇒ Object (readonly)
Returns the value of attribute villages.
6 7 8 |
# File 'lib/swiss_village_directory/repository.rb', line 6 def villages @villages end |
Instance Method Details
#find_all_by(find_params) ⇒ Object
33 34 35 |
# File 'lib/swiss_village_directory/repository.rb', line 33 def find_all_by(find_params) @villages.find_all { |v| all_filters_matched?(v, find_params) } end |