class Gh::Trending::Parsers::Parser

Abstract parser of the trending page.

Attributes

agent[R]

Public Class Methods

new(agent = nil) click to toggle source
# File lib/gh_trending/parsers/parser.rb, line 10
def initialize(agent = nil)
  @agent = agent || default_agent
end

Public Instance Methods

parse() click to toggle source
# File lib/gh_trending/parsers/parser.rb, line 14
def parse
  raise NotImplementedError
end

Protected Instance Methods

build_github_url(url) click to toggle source

Prepends the github's website URL for a given parsed url. url can be a repository url or a developer url.

url has the format: /some/url, because that's the format returned to us by the crawler

# File lib/gh_trending/parsers/parser.rb, line 25
def build_github_url(url)
  "https://github.com#{url}"
end
build_request_url_with(parser_args) click to toggle source
# File lib/gh_trending/parsers/parser.rb, line 29
def build_request_url_with(parser_args)
  return resource_url if parser_args.no_args?

  url = resource_url
  url += "/#{parser_args.language}" if parser_args.language
  url += "?since=#{parser_args.time_period}" if parser_args.time_period
  url
end
resource_url() click to toggle source
# File lib/gh_trending/parsers/parser.rb, line 38
def resource_url
  raise NotImplementedError
end

Private Instance Methods

default_agent() click to toggle source
# File lib/gh_trending/parsers/parser.rb, line 44
def default_agent
  Mechanize.new
end