Class: Parser::Base
- Inherits:
-
Object
- Object
- Parser::Base
- Defined in:
- lib/fly_parser/base.rb
Overview
Html Base
Instance Method Summary collapse
- #collect_between(first, last) ⇒ Object
- #copyright(options) ⇒ Object
-
#initialize(url, options) ⇒ Base
constructor
A new instance of Base.
- #next_page(css_selector) ⇒ Object
- #parse_all ⇒ Object
- #parse_page ⇒ Object
Constructor Details
#initialize(url, options) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 |
# File 'lib/fly_parser/base.rb', line 5 def initialize(url, ) @source = Parser.connect(url) @copyright = copyright() @limit_pages ||= 5 @delay ||= 10 end |
Instance Method Details
#collect_between(first, last) ⇒ Object
34 35 36 37 |
# File 'lib/fly_parser/base.rb', line 34 def collect_between(first, last) return nil if first.nil? first == last ? [first] : [first, *collect_between(first.next, last)] end |
#copyright(options) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/fly_parser/base.rb', line 38 def copyright() source = [:source] { url: source['copyright'], title: source['copyright_title'] } end |
#next_page(css_selector) ⇒ Object
12 13 14 |
# File 'lib/fly_parser/base.rb', line 12 def next_page(css_selector) @next_page = @source.links_with(css_selector)[0] end |
#parse_all ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fly_parser/base.rb', line 16 def parse_all result = parse_page next_page() #concat all pages into one array i = 1 ap "Parsing #{i} page" until @next_page.nil? || i == @limit_pages sleep @delay i += 1 ap "Parsing #{i} page" @source = @next_page.click next_page() result.concat(parse_page) end result end |
#parse_page ⇒ Object
32 33 |
# File 'lib/fly_parser/base.rb', line 32 def parse_page end |