Class: WrfForecast::Parameter::ParameterRepository

Inherits:
RubyUtils::Parameter::BaseParameterRepository
  • Object
show all
Defined in:
lib/wrf_forecast/parameter/parameter_repository.rb

Overview

Parameter repository to store the valid parameters of the script. #initialize gets the provided parameters and fills a hash which grants access to the provided parameters and arguments.

Instance Method Summary collapse

Instance Method Details

#create_defaultsObject (private)

method to set the default values when parameter –default is set



45
46
47
48
49
# File 'lib/wrf_forecast/parameter/parameter_repository.rb', line 45

def create_defaults
  @parameters[:date] = Time.parse("00:00").to_s
  @parameters[:period] = "24"
  @parameters[:default] = true
end

#define_mappingObject (private)

method to define the input string values that will match a given paramter symbol



33
34
35
36
37
38
39
40
41
42
# File 'lib/wrf_forecast/parameter/parameter_repository.rb', line 33

def define_mapping
  @mapping[:aggregate] = ["-a", "--aggregate"]
  @mapping[:date] = ["-d", "--date"]
  @mapping[:default] = ["--default"]
  @mapping[:json] = ["-j", "--json"]
  @mapping[:locale] = ["-l", "--locale"]
  @mapping[:offset] = ["-o", "--offset"]
  @mapping[:period] = ["-p", "--period"]
  @mapping[:save] = ["-s", "--save"]
end

#process_argument(arg) ⇒ Object (private)

method to read further argument and process it depending on its content

Parameters:

  • arg (String)

    the given argument



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wrf_forecast/parameter/parameter_repository.rb', line 16

def process_argument(arg)
  case arg
    when *@mapping[:aggregate] then @parameters[:aggregate] = true
    when *@mapping[:date] then create_argument_entry(:date)
    when *@mapping[:default] then create_defaults
    when *@mapping[:json] then @parameters[:json] = true
    when *@mapping[:locale] then create_argument_entry(:locale)
    when *@mapping[:offset] then create_argument_entry(:offset)
    when *@mapping[:period] then create_argument_entry(:period)
    when *@mapping[:save] then create_argument_entry(:save)
  else
    raise_invalid_parameter(arg)
  end
  nil
end