Class: Gh::Trending::Parsers::ReposParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/gh_trending/parsers/repos_parser.rb

Overview

Parses the trending repositories page

Constant Summary collapse

LIST_WITH_REPO_NODES_HTML_CLASS =
'ol.repo-list'.freeze
DIV_WITH_DESCRIPTION =
'div.py-1'.freeze
SPAN_WITH_LANGUAGE =
'span.mr-3'.freeze
SPAN_WITH_STARS =
'span.float-right'.freeze

Instance Attribute Summary

Attributes inherited from Parser

#agent

Instance Method Summary collapse

Methods inherited from Parser

#initialize

Constructor Details

This class inherits a constructor from Gh::Trending::Parsers::Parser

Instance Method Details

#parse(parser_args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gh_trending/parsers/repos_parser.rb', line 11

def parse(parser_args)
  url = build_request_url_with(parser_args)
  page = agent.get(url)
  parsed_page = page.at(LIST_WITH_REPO_NODES_HTML_CLASS)

  if parsed_page.nil?
    changed_page = :front_page_with_repos
    error = Gh::Trending::Parsers::HtmlChangedError.new(changed_page)
    raise error
  end

  repositories = parsed_page.search('li')
  build_repositories_from_node(repositories)
end

#resource_urlObject



26
27
28
# File 'lib/gh_trending/parsers/repos_parser.rb', line 26

def resource_url
  'https://github.com/trending'.freeze
end