class AudioBookCreator::Web

Attributes

count[RW]

@!attribute count

@return Integer the number of pages visited
max[RW]

@!attribute max

@return Integer the maximum number of pages to visit

Public Class Methods

new(max = nil) click to toggle source
# File lib/audio_book_creator/web.rb, line 16
def initialize(max = nil)
  @max = max
  @count = 0
end

Public Instance Methods

[](url) click to toggle source
# File lib/audio_book_creator/web.rb, line 21
def [](url)
  @count += 1
  log_page(url)
  check_limit
  open(url.to_s).read
end

Private Instance Methods

check_limit() click to toggle source
# File lib/audio_book_creator/web.rb, line 36
def check_limit
  raise "visited #{max} pages" if over_limit?
end
log_page(url) click to toggle source
# File lib/audio_book_creator/web.rb, line 30
def log_page(url)
  logger.info do
    max ? "fetch  #{url} [#{count}/#{max}]" : "fetch  #{url} [#{count}]"
  end
end
over_limit?() click to toggle source
# File lib/audio_book_creator/web.rb, line 40
def over_limit?
  max && count > max
end