Class: Gribr::Degrib::InventoryRecord

Inherits:
Struct
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RegexpParser

included

Instance Attribute Details

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def description
  @description
end

#elementObject

Returns the value of attribute element

Returns:

  • (Object)

    the current value of element



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def element
  @element
end

#end_positionObject

Returns the value of attribute end_position

Returns:

  • (Object)

    the current value of end_position



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def end_position
  @end_position
end

#levelObject

Returns the value of attribute level

Returns:

  • (Object)

    the current value of level



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def level
  @level
end

#numberObject

Returns the value of attribute number

Returns:

  • (Object)

    the current value of number



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def number
  @number
end

#reference_timeObject

Returns the value of attribute reference_time

Returns:

  • (Object)

    the current value of reference_time



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def reference_time
  @reference_time
end

#start_positionObject

Returns the value of attribute start_position

Returns:

  • (Object)

    the current value of start_position



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def start_position
  @start_position
end

#unitObject

Returns the value of attribute unit

Returns:

  • (Object)

    the current value of unit



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def unit
  @unit
end

#valid_timeObject

Returns the value of attribute valid_time

Returns:

  • (Object)

    the current value of valid_time



6
7
8
# File 'lib/gribr/degrib/inventory_record.rb', line 6

def valid_time
  @valid_time
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of 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

.regexpObject



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_previousObject



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_sObject



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