class Noaaish::Extractor

Constants

NOAA_FIELDS

Attributes

format[R]
input[R]

Public Class Methods

new(input, output=destination, format=:hash) click to toggle source
# File lib/noaaish/extractor.rb, line 6
def initialize(input, output=destination, format=:hash)
  @input = input
  @destination = output
  @format = format
end

Public Instance Methods

call() click to toggle source
# File lib/noaaish/extractor.rb, line 14
def call
  # For each line, create a json record.
  hash = input.each_line.map { |line|
    NOAA_FIELDS.inject({}) do |hash, (field, range)|
      hash.merge(field => line[range])
    end
  }

  case format
  when :json
    destination << hash.to_json
    destination
  when :hash
    hash
  end
end
destination() click to toggle source
# File lib/noaaish/extractor.rb, line 31
def destination
  @destination ||= Tempfile.new('noaaish-translator')
end