Class: BcCrawler::Main
- Inherits:
-
Object
- Object
- BcCrawler::Main
- Defined in:
- lib/bc_crawler/main.rb
Instance Attribute Summary collapse
-
#releases ⇒ Object
Returns the value of attribute releases.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #crawl ⇒ Object
-
#initialize(url) ⇒ Main
constructor
A new instance of Main.
- #to_s ⇒ Object
Constructor Details
#initialize(url) ⇒ Main
Returns a new instance of Main.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bc_crawler/main.rb', line 10 def initialize(url) @url = url @releases = [] # call the page html = open(@url).read release_paths = Set.new # get all "a" elements that target an /album/... URL html.scan(/<a href="\/album\/(.*?)"/).each { |r| release_paths << "/album/#{r.first}" } # TODO: implement single tracks, that are not assigned to an album, but directly to the artist # initialize the release(s) release_paths.each do |path| @releases << BcCrawler::Release.new("#{ @url }#{ path }") end end |
Instance Attribute Details
#releases ⇒ Object
Returns the value of attribute releases.
8 9 10 |
# File 'lib/bc_crawler/main.rb', line 8 def releases @releases end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/bc_crawler/main.rb', line 8 def url @url end |
Instance Method Details
#crawl ⇒ Object
29 30 31 32 33 34 |
# File 'lib/bc_crawler/main.rb', line 29 def crawl # fetch information about the release @releases.each do |release| release.crawl end end |
#to_s ⇒ Object
36 37 38 39 40 41 |
# File 'lib/bc_crawler/main.rb', line 36 def to_s <<-EOF URL : #{ @url } Number of releases : #{ @releases.count } EOF end |