Sha256: 15ac82ddb4663ae08aa797f0b89cdfe009ec823bd4969e8aad4070928d809ec2

Contents?: true

Size: 737 Bytes

Versions: 4

Compression:

Stored size: 737 Bytes

Contents

Prospectus.extra_dep('url_xpath', 'nokogiri')

require 'open-uri'

module LogCabin
  module Modules
    ##
    # Pull state from a GitHub tag
    module UrlXpath
      include Prospectus.helpers.find(:regex)

      def load!
        raise('No url provided') unless @url
        raise('No xpath provided') unless @xpath
        text = parse_page
        @state.value = regex_helper(text)
      end

      private

      def parse_page
        page = open(@url) # rubocop:disable Security/Open
        html = Nokogiri::HTML(page) { |config| config.strict.nonet }
        html.xpath(@xpath).text.strip
      end

      def url(value)
        @url = value
      end

      def xpath(value)
        @xpath = value
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
prospectus-0.8.0 lib/prospectus/modules/url_xpath.rb
prospectus-0.6.0 lib/prospectus/modules/url_xpath.rb
prospectus-0.5.8 lib/prospectus/modules/url_xpath.rb
prospectus-0.5.7 lib/prospectus/modules/url_xpath.rb