Class: Barcade::Scraper
- Inherits:
-
Object
- Object
- Barcade::Scraper
- Defined in:
- lib/barcade/scraper.rb
Constant Summary collapse
- BASE_URI =
'http://barcadebrooklyn.com/'
Instance Attribute Summary collapse
-
#date_slug ⇒ Object
Returns the value of attribute date_slug.
Instance Method Summary collapse
- #blog_post ⇒ Object
-
#initialize(date) ⇒ Scraper
constructor
A new instance of Scraper.
- #tap ⇒ Object
Constructor Details
#initialize(date) ⇒ Scraper
Returns a new instance of Scraper.
9 10 11 |
# File 'lib/barcade/scraper.rb', line 9 def initialize(date) @date_slug = date.strftime('%Y/%m/%d/') end |
Instance Attribute Details
#date_slug ⇒ Object
Returns the value of attribute date_slug.
7 8 9 |
# File 'lib/barcade/scraper.rb', line 7 def date_slug @date_slug end |
Instance Method Details
#blog_post ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/barcade/scraper.rb', line 18 def blog_post agent = Mechanize.new begin post = agent.get("#{BASE_URI}#{self.date_slug}") rescue Mechanize::ResponseCodeError => e puts "Today's tap hasn't been posted yet. Try the --yesterday flag." exit end end |
#tap ⇒ Object
13 14 15 16 |
# File 'lib/barcade/scraper.rb', line 13 def tap body = blog_post.search('section.entry > p').text body.split(/\n/) end |