class GemUpdater::ChangelogParser::GithubParser

ChangelogParser is responsible for parsing a changelog hosted on github.

Constants

ANCHOR_XPATH

Attributes

uri[R]
version[R]

Public Class Methods

new(uri:, version:) click to toggle source

@param uri [String] changelog uri @param version [String] version of gem

# File lib/gem_updater/changelog_parser/github_parser.rb, line 16
def initialize(uri:, version:)
  @uri     = uri
  @version = version
end

Public Instance Methods

changelog() click to toggle source

Finds anchor in changelog, otherwise return the base uri.

@return [String] the URL of changelog

# File lib/gem_updater/changelog_parser/github_parser.rb, line 24
def changelog
  uri + find_anchor(document).to_s
end

Private Instance Methods

document() click to toggle source

Opens changelog url and parses it.

@return [Nokogiri::HTML4::Document] the changelog

# File lib/gem_updater/changelog_parser/github_parser.rb, line 33
def document
  Nokogiri::HTML(URI.parse(uri).open, nil, Encoding::UTF_8.to_s)
end
find_anchor(doc) click to toggle source

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

@param doc [Nokogiri::HTML4::Document] document @return [String, nil] anchor’s href

# File lib/gem_updater/changelog_parser/github_parser.rb, line 41
def find_anchor(doc)
  anchor = doc.xpath(ANCHOR_XPATH).find do |element|
    element.attr('href').match(version.delete('.'))
  end
  return unless anchor

  anchor.attr('href').gsub(%(\\"), '')
end