Class: Gribr::Degrib::InventoryRecord
- Inherits:
-
Struct
- Object
- Struct
- Gribr::Degrib::InventoryRecord
- Includes:
- RegexpParser
- Defined in:
- lib/gribr/degrib/inventory_record.rb
Constant Summary collapse
- REGEXP_ELEMENT =
Regexp.new('(([^=]+)="(.*\[(.+)\])")').freeze
- REGEXP_FLOAT =
Regexp.new('((\+|-)?\d+.?\d*)').freeze
- REGEXP_INTEGER =
Regexp.new('(\d+)').freeze
- REGEXP_LEVEL =
Regexp.new('([^,]+)').freeze
- REGEXP_TIMESTAMP =
Regexp.new('((\d{2})/(\d{2})/(\d{4})\s+(\d{2}):(\d{2}))').freeze
- TIME_FORMAT =
"%m/%d/%Y %H:%M".freeze
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#element ⇒ Object
Returns the value of attribute element.
-
#end_position ⇒ Object
Returns the value of attribute end_position.
-
#level ⇒ Object
Returns the value of attribute level.
-
#number ⇒ Object
Returns the value of attribute number.
-
#reference_time ⇒ Object
Returns the value of attribute reference_time.
-
#start_position ⇒ Object
Returns the value of attribute start_position.
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#valid_time ⇒ Object
Returns the value of attribute valid_time.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
Methods included from RegexpParser
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def description @description end |
#element ⇒ Object
Returns the value of attribute element
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def element @element end |
#end_position ⇒ Object
Returns the value of attribute end_position
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def end_position @end_position end |
#level ⇒ Object
Returns the value of attribute level
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def level @level end |
#number ⇒ Object
Returns the value of attribute number
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def number @number end |
#reference_time ⇒ Object
Returns the value of attribute reference_time
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def reference_time @reference_time end |
#start_position ⇒ Object
Returns the value of attribute start_position
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def start_position @start_position end |
#unit ⇒ Object
Returns the value of attribute unit
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def unit @unit end |
#valid_time ⇒ Object
Returns the value of attribute valid_time
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def valid_time @valid_time end |
#version ⇒ Object
Returns the value of attribute version
6 7 8 |
# File 'lib/gribr/degrib/inventory_record.rb', line 6 def version @version end |
Class Method Details
.build(match_data) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gribr/degrib/inventory_record.rb', line 54 def build(match_data) if match_data record = new record.number = match_data[1].to_i record.start_position = match_data[3].to_i record.version = match_data[4].to_i record.element = match_data[6] record.description = match_data[7] record.unit = match_data[8] record.level = match_data[9] record.reference_time = Time.utc(match_data[13].to_i, match_data[11].to_i, match_data[12].to_i, match_data[14].to_i, match_data[15].to_i) record.valid_time = Time.utc(match_data[19].to_i, match_data[17].to_i, match_data[18].to_i, match_data[20].to_i, match_data[21].to_i) record end end |
.regexp ⇒ Object
72 73 74 |
# File 'lib/gribr/degrib/inventory_record.rb', line 72 def regexp @regexp ||= Regexp.new([REGEXP_FLOAT, REGEXP_INTEGER, REGEXP_INTEGER, REGEXP_ELEMENT, REGEXP_LEVEL, REGEXP_TIMESTAMP, REGEXP_TIMESTAMP].join('\s*,\s*')).freeze end |
Instance Method Details
#end_position_of_previous ⇒ Object
18 19 20 |
# File 'lib/gribr/degrib/inventory_record.rb', line 18 def end_position_of_previous start_position - 1 if number > 1 end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/gribr/degrib/inventory_record.rb', line 22 def to_s [ formatted_number, start_position, version, formatted_element, level, formatted_reference_time, formatted_valid_time, formatted_projection ].join(", ") end |