Class: Barcade::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/barcade/scraper.rb

Constant Summary collapse

BASE_URI =
'http://barcadebrooklyn.com/'

Instance Attribute Summary collapse

Instance Method Summary collapse

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_slugObject

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_postObject



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

#tapObject



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