Class: WrfLibrary::Location::LocationMapping
- Inherits:
-
Object
- Object
- WrfLibrary::Location::LocationMapping
- Defined in:
- lib/wrf_library/data/location_mapping.rb
Overview
TODO:
this class is only used in tests at the moment
Simple data class to store a hash mapping from a location key to a location name The csv formatted input file need to contain key;location pairs for each entry
Instance Attribute Summary collapse
-
#locations ⇒ Hash
readonly
private
The mapping of location key and location name.
Instance Method Summary collapse
-
#create_mapping(location_file) ⇒ Object
private
method to read the mapping file and generate the hash mapping for the locations.
-
#get_file_to_location(location_shortcut) ⇒ String
method to return the location name to a given key.
-
#initialize(location_file) ⇒ LocationMapping
constructor
initialization.
Constructor Details
#initialize(location_file) ⇒ LocationMapping
initialization
16 17 18 19 |
# File 'lib/wrf_library/data/location_mapping.rb', line 16 def initialize(location_file) @locations = Hash.new() create_mapping(location_file) end |
Instance Attribute Details
#locations ⇒ Hash (readonly, private)
Returns the mapping of location key and location name.
30 31 32 |
# File 'lib/wrf_library/data/location_mapping.rb', line 30 def locations @locations end |
Instance Method Details
#create_mapping(location_file) ⇒ Object (private)
method to read the mapping file and generate the hash mapping for the locations
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/wrf_library/data/location_mapping.rb', line 34 def create_mapping(location_file) data = RubyUtils::FileReader.new(location_file, ";").data data.each { |line| if (line.length == 2 && line[0] != nil && line[1] != nil) @locations[line[0]] = line[1] else raise ArgumentError, "Error: Location file contains invalid location pair".red end } nil end |
#get_file_to_location(location_shortcut) ⇒ String
method to return the location name to a given key
23 24 25 |
# File 'lib/wrf_library/data/location_mapping.rb', line 23 def get_file_to_location(location_shortcut) @locations.fetch(location_shortcut, nil) end |