Class: Noaaish::Extractor
- Inherits:
-
Object
- Object
- Noaaish::Extractor
- Defined in:
- lib/noaaish/extractor.rb
Constant Summary collapse
- NOAA_FIELDS =
YYYYMMDDHH
{'HR_TIME' => (13...23), # YYYYMMDDHH 'HR' => (21...23), 'MN' => (23...25), 'DIR' => (26...29), 'SPD' => (30...33), 'GUS' => (34...37), 'CLG' => (38...41), 'SKC' => (42...45), 'L' => (46...47), 'M' => (48...49), 'H' => (50...51), 'VSB' => (52...56), 'MW1' => (57...59), 'MW2' => (60...62), 'MW3' => (63...65), 'MW4' => (66...68), 'AW1' => (69...71), 'AW2' => (72...74), 'AW3' => (75...77), 'AW4' => (78...80), 'W' => (81...82), 'TEMP' => (83...87), 'DEWP' => (88...92), 'SLP' => (93...99), 'ALT' => (100...105), 'STP' => (106...112), 'MAX' => (113...116), 'MIN' => (117...120), 'PCP01' => (121...126), 'PCP06' => (127...132), 'PCP24' => (133...138), 'PCPXX' => (139...144), 'SD' => (145...147),}
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #call ⇒ Object
- #destination ⇒ Object
-
#initialize(input, output = destination) ⇒ Extractor
constructor
A new instance of Extractor.
Constructor Details
#initialize(input, output = destination) ⇒ Extractor
Returns a new instance of Extractor.
6 7 8 9 |
# File 'lib/noaaish/extractor.rb', line 6 def initialize(input, output=destination) @input = input @destination = output end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
11 12 13 |
# File 'lib/noaaish/extractor.rb', line 11 def input @input end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/noaaish/extractor.rb', line 13 def call # For each line, create a json record. destination.write(input.each_line.map { |line| NOAA_FIELDS.inject({}) do |hash, (field, range)| hash.merge(field => line[range]) end } .to_json) destination end |
#destination ⇒ Object
24 25 26 |
# File 'lib/noaaish/extractor.rb', line 24 def destination @destination ||= Tempfile.new('noaaish-translator') end |