Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: c4e2d8d451
Fetching contributors…

Cannot retrieve contributors at this time

30 lines (24 sloc) 1.055 kB
Parser class
Nat Budin and Wyatt Greene (@natbudin and @techiferous)
The Parser class (app/models/parser.rb) is a generic parser for EPIC-style
tweets. You specify the text of a tweet and a list of hash tags to use as
"keys" (i.e. data you want to specifically handle), and it will give you a
Hash containing a the tweet's context split out into a key/value mapping.
@parser =
@parser.valid_keys = %w{loc offer contact}
@parser.text = "#haiti #offer hospital #Loc 75 miles from PaP #contact Tim 413-241-6526 or"
@map = @parser.parse
# @map should be:
# {
# "offer" => "hospital",
# "loc" => "75 miles from PaP"
# "contact" => "Tim 413-241-6526 or"
# "extra" => "#haiti"
# }
An automated test suite is available in test/units/parser_test.rb.
Additionally, a corpus of real data collected by Wyatt is available in
test/sample_tweet_data.rb, which is used by part of the unit test suite to
verify that these parse without breaking.
Jump to Line
Something went wrong with that request. Please try again.