Created
March 13, 2018 02:09
-
-
Save sean2121/229b42e48746891f1fcb6478543b2601 to your computer and use it in GitHub Desktop.
parser.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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