Class: FesomPossibleVar
- Inherits:
-
Object
- Object
- FesomPossibleVar
- Defined in:
- lib/fesom_possible_var.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#time_method ⇒ Object
readonly
Returns the value of attribute time_method.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#variable_id ⇒ Object
readonly
Returns the value of attribute variable_id.
Class Method Summary collapse
-
.create_from_fortran_code(code, sort: true) ⇒ Array<FesomPossibleVar>
Generates a collection of FesomPossibleVar objects based upon a FORTRAN code snippet.
Instance Method Summary collapse
-
#initialize(variable_id, unit, description, time_method) ⇒ FesomPossibleVar
constructor
A new instance of FesomPossibleVar.
-
#to_s ⇒ String
Helper method to nicely print out this FesomPossibleVar.
Constructor Details
#initialize(variable_id, unit, description, time_method) ⇒ FesomPossibleVar
Returns a new instance of FesomPossibleVar.
7 8 9 10 11 12 |
# File 'lib/fesom_possible_var.rb', line 7 def initialize(variable_id, unit, description, time_method) @variable_id = variable_id @unit = unit @description = description @time_method = time_method end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/fesom_possible_var.rb', line 5 def description @description end |
#time_method ⇒ Object (readonly)
Returns the value of attribute time_method.
5 6 7 |
# File 'lib/fesom_possible_var.rb', line 5 def time_method @time_method end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
5 6 7 |
# File 'lib/fesom_possible_var.rb', line 5 def unit @unit end |
#variable_id ⇒ Object (readonly)
Returns the value of attribute variable_id.
5 6 7 |
# File 'lib/fesom_possible_var.rb', line 5 def variable_id @variable_id end |
Class Method Details
.create_from_fortran_code(code, sort: true) ⇒ Array<FesomPossibleVar>
Generates a collection of FesomPossibleVar objects based upon a FORTRAN code snippet
Maps each line of the argument [String] code via a regex based upon the initialization of this class, using attributes <variable_id>, <description>, and <unit>.
Special handling of the variable “tso”, which uses TimeMethods::POINT instead of the default TimeMethods::Mean
TODO(PG – Reverse Engineering): I still need to find out of the regex needs the parameters or if instead it is used to **figure out what values they should have for initialization**.
NOTE(PG – Reverse Engineering): This looks like the Ruby equivalent of a Python `classmethod` and seems to implement an alternative way of constructing objects of this class.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fesom_possible_var.rb', line 32 def self.create_from_fortran_code(code, sort: true) vars = code.split("\n").map do |init_line| /.+?, ['"](?<variable_id>[^,]+?)['"], ['"](?<description>.+?)['"], ['"](?<unit>[^,]+?)['"]\) *.*/ =~ init_line raise "could not parse all values: variable_id:#{variable_id.inspect}, unit:#{unit.inspect}, description:#{description.inspect}, code:'#{init_line}'" unless [variable_id, unit, description].all? if(variable_id == "tso") FesomPossibleVar.new variable_id, unit, description, TimeMethods::POINT else FesomPossibleVar.new variable_id, unit, description, TimeMethods::MEAN end end if(sort) vars.sort_by {|v| v.variable_id} else vars end end |
Instance Method Details
#to_s ⇒ String
Helper method to nicely print out this FesomPossibleVar.
52 53 54 |
# File 'lib/fesom_possible_var.rb', line 52 def to_s "#{@variable_id}: '#{@unit}' #{@time_method} '#{@description}'" end |