Class: WrfLibrary::JsonConverter::BaseStationJsonConverter
- Inherits:
-
Object
- Object
- WrfLibrary::JsonConverter::BaseStationJsonConverter
- Defined in:
- lib/wrf_library/json_converter/base_station_converter.rb
Overview
Abstract parent class for the json converter to convert preread weather data into the specified output format. The metadata is identical for all child classes, the weather values can depend on the different attributes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ DataRepository
readonly
private
The data repository.
Instance Method Summary collapse
-
#add_additions ⇒ Object
private
abstract method which allows additions to the meta data hash if present method.
-
#convert(filepath = nil) ⇒ String
method to convert the data of repository into the given json output if nil the output will be printed to stdout.
-
#generate_data_values ⇒ Object
private
abstract method which adds the weather data to the weather key that will be converted into json via a Hash.
-
#generate_meta_hash ⇒ Hash
private
methode to create the meta entry based on the meta data in the repoitory json conversion.
-
#generate_station_hash(station) ⇒ Hash
private
method to create the station entry based on the meta data in the repository json conversion.
-
#initialize(repository) ⇒ BaseStationJsonConverter
constructor
initialization.
Constructor Details
#initialize(repository) ⇒ BaseStationJsonConverter
initialization
17 18 19 |
# File 'lib/wrf_library/json_converter/base_station_converter.rb', line 17 def initialize(repository) @data = repository end |
Instance Attribute Details
#data ⇒ DataRepository (readonly, private)
Returns the data repository.
42 43 44 |
# File 'lib/wrf_library/json_converter/base_station_converter.rb', line 42 def data @data end |
Instance Method Details
#add_additions ⇒ Object (private)
abstract method which allows additions to the meta data hash if present method
73 74 75 76 |
# File 'lib/wrf_library/json_converter/base_station_converter.rb', line 73 def add_additions fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: add_additions from its base class".red end |
#convert(filepath = nil) ⇒ String
method to convert the data of repository into the given json output if nil the output will be printed to stdout
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/wrf_library/json_converter/base_station_converter.rb', line 25 def convert(filepath=nil) output = Hash.new() output[:meta_data] = () output[:weather_data] = generate_data_values() output_string = JSON.pretty_generate(output) if (filepath != nil) file = File.open(File.join(filepath,"output.json"), "w") file.write(output_string) file.close end return output_string end |
#generate_data_values ⇒ Object (private)
abstract method which adds the weather data to the weather key that will be converted into json via a Hash. If this method implements faulty Hashes the json conversion will fail. method
83 84 85 86 |
# File 'lib/wrf_library/json_converter/base_station_converter.rb', line 83 def generate_data_values fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: generate_data_values from its base class".red end |
#generate_meta_hash ⇒ Hash (private)
methode to create the meta entry based on the meta data in the repoitory json conversion
47 48 49 50 51 52 53 54 |
# File 'lib/wrf_library/json_converter/base_station_converter.rb', line 47 def = @data. = Hash.new() [:station] = generate_station_hash(.station) [:start_date] = .start_date = .merge(add_additions()) return end |
#generate_station_hash(station) ⇒ Hash (private)
method to create the station entry based on the meta data in the repository json conversion
60 61 62 63 64 65 66 67 68 |
# File 'lib/wrf_library/json_converter/base_station_converter.rb', line 60 def generate_station_hash(station) station_hash = Hash.new() station_hash[:name] = station.name station_hash[:descriptor] = station.descriptor station_hash[:elevation] = station.elevation station_hash[:coordinate] = { :x => station.coordinate.x, :y => station.coordinate.y } return station_hash end |