Skip to content

Instantly share code, notes, and snippets.

@sean2121
Created March 13, 2018 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean2121/229b42e48746891f1fcb6478543b2601 to your computer and use it in GitHub Desktop.
Save sean2121/229b42e48746891f1fcb6478543b2601 to your computer and use it in GitHub Desktop.
parser.rb
class Parser
class Error < StandardError; end
def initialize(row)
raise ArgumentError unless row.kind_of?(String)
CSV.parse(row) do |i|
@row_csv = i.map(&:freeze).freeze
end
raise Error, "Incorrect Format" if @row_csv.size > 16
end
def parse()
token = [
:type, :test, :announce_time, :situation,
:number, :earthquake_id, :earthquake_time, :latitude_s, :longitude_s,
:region, :depth, :mjma, :max_shindo, :land_sea, :continues
].freeze
Hash[token.zip @row_csv]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment