class GemUpdater::SourcePageParser::GitHubParser

GitHubParser is responsible for parsing source code hosted on github.com.

Constants

BASE_URL

Attributes

doc[R]
version[R]

Public Class Methods

new(doc, version) click to toggle source

@param doc [Nokogiri::XML::Element] document of source page @param version [String] version of gem rubocop:disable Lint/MissingSuper

# File lib/gem_updater/source_page_parser.rb, line 122
def initialize(doc, version)
  @doc     = doc
  @version = version
end

Public Instance Methods

changelog() click to toggle source

Finds url of changelog.

@return [String] the URL of changelog

# File lib/gem_updater/source_page_parser.rb, line 131
def changelog
  url = find_changelog_link
  return unless url

  full_url = BASE_URL + url

  if changelog_may_contain_anchor?(full_url)
    anchor = find_anchor(full_url)
    full_url += anchor if anchor
  end

  full_url
end

Private Instance Methods

find_anchor(url) click to toggle source

Looks into document to find it there is an anchor to new gem version.

@param url [String] url of changelog @return [String, nil] anchor's href

# File lib/gem_updater/source_page_parser.rb, line 162
def find_anchor(url)
  changelog_page = Nokogiri::HTML(URI.parse(url).open)
  anchor = changelog_page.css(%(a.anchor)).find do |element|
    element.attr('href').match(version.delete('.'))
  end

  anchor&.attr('href')
end