Class: Parser::Sport

Inherits:
Object
  • Object
show all
Defined in:
lib/fly_parser/sources/sport.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Sport

Returns a new instance of Sport.



4
5
6
7
# File 'lib/fly_parser/sources/sport.rb', line 4

def initialize(source)
  @source = Parser.connect(source)
  @categories = %w(Футбол Хоккей Баскетбол Авто/мото Теннис)
end

Instance Method Details

#current_pageObject



19
20
21
# File 'lib/fly_parser/sources/sport.rb', line 19

def current_page
  @source.link_with(:text => @category).click
end

#parse_allObject



23
24
25
# File 'lib/fly_parser/sources/sport.rb', line 23

def parse_all
  @categories.map { |category| parse_in(category) }
end

#parse_in(category) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/fly_parser/sources/sport.rb', line 9

def parse_in(category)
  @category = category
  @current_page = current_page
  @current_page.search('.anons').map do |news_item|
    href = news_item.css('a').first.attributes['href'].value
    item_page = @current_page.link_with(:href => href).click
    { title: item_page.search('.titleH1').text(), content: item_page.search('.article-textBlock').text() }
  end  
end