Class: Gribr::Degrib::ProbeRecord

Inherits:
Struct
  • Object
show all
Includes:
RegexpParser
Defined in:
lib/gribr/degrib/probe_record.rb

Constant Summary collapse

REGEXP_ELEMENT =
Regexp.new("(.*)").freeze
REGEXP_FLOAT =
Regexp.new("((\\+|-)?\\d+.?\\d*)").freeze
REGEXP_LOCATION =
Regexp.new("((#{REGEXP_FLOAT}),(#{REGEXP_FLOAT}))").freeze
REGEXP_TIMESTAMP =
Regexp.new("(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})").freeze
REGEXP_UNIT =
Regexp.new("([^)]+)").freeze
SEPARATOR =
"\t".freeze
TIME_FORMAT =
"%Y-%m-%d %H:%M:%S".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RegexpParser

included

Instance Attribute Details

#elementObject

Returns the value of attribute element

Returns:

  • (Object)

    the current value of element



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

def element
  @element
end

#latitudeObject

Returns the value of attribute latitude

Returns:

  • (Object)

    the current value of latitude



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

def latitude
  @latitude
end

#longitudeObject

Returns the value of attribute longitude

Returns:

  • (Object)

    the current value of longitude



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

def longitude
  @longitude
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/probe_record.rb', line 6

def reference_time
  @reference_time
end

#unitObject

Returns the value of attribute unit

Returns:

  • (Object)

    the current value of unit



6
7
8
# File 'lib/gribr/degrib/probe_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/probe_record.rb', line 6

def valid_time
  @valid_time
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



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

def value
  @value
end

Class Method Details

.build(match_data) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gribr/degrib/probe_record.rb', line 31

def build(match_data)

  if match_data
    record = new
    record.latitude = match_data[3].to_f
    record.longitude = match_data[6].to_f
    record.element = match_data[8]
    record.unit = match_data[9]
    record.reference_time = Time.utc(*match_data[10..14].map(&:to_i))
    record.valid_time = Time.utc(*match_data[15..19].map(&:to_i))
    record.value = match_data[20].to_f
    record
  end

end

.regexpObject



47
48
49
# File 'lib/gribr/degrib/probe_record.rb', line 47

def regexp
  @regexp ||= Regexp.new("\\(#{REGEXP_LOCATION}\\),\\s+#{REGEXP_ELEMENT}\\[#{REGEXP_UNIT}\\],\\s+#{REGEXP_TIMESTAMP},\\s+#{REGEXP_TIMESTAMP},\\s+#{REGEXP_FLOAT}").freeze
end

Instance Method Details

#to_s(options = {}) ⇒ Object



19
20
21
# File 'lib/gribr/degrib/probe_record.rb', line 19

def to_s(options = {})
  [ latitude.to_s, longitude.to_s, element, unit, format_time(reference_time, options), format_time(valid_time, options), value.to_s ].join(SEPARATOR)
end