Sha256: a4c4358756eb1aab0c51c63c4c59f0670731a4c64f8a25aa9927034a5aaae0df

Contents?: true

Size: 958 Bytes

Versions: 21

Compression:

Stored size: 958 Bytes

Contents

require "hpricot"

module Integrity
  class Notifier
    module Test
      # Thanks Harry! http://gist.github.com/39960
      class HpricotMatcher
        def initialize(html)
          @doc = Hpricot(html)
        end

        # elements('h1') returns a Hpricot::Elements object with all h1-tags.
        def elements(selector)
          @doc.search(selector)
        end

        # element('h1') returns Hpricot::Elem with first h1-tag, or nil if
        # none exist.
        def element(selector)
          @doc.at(selector)
        end

        # tags('h1') returns the inner HTML of all matched elements mathed.
        def tags(selector)
          e = elements(selector)
          e.map {|x| x.inner_html}
        end

        # tag('h1') returns the inner HTML of the first mached element, or
        # nil if none matched.
        def tag(selector)
          e = element(selector)
          e && e.inner_html
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 6 rubygems

Version Path
alphasights-integrity-0.1.10 lib/integrity/notifier/test/hpricot_matcher.rb
alphasights-integrity-0.1.9.3 lib/integrity/notifier/test/hpricot_matcher.rb
alphasights-integrity-0.1.9.4 lib/integrity/notifier/test/hpricot_matcher.rb
alphasights-integrity-0.1.9.5 lib/integrity/notifier/test/hpricot_matcher.rb
alphasights-integrity-0.1.9.6 lib/integrity/notifier/test/hpricot_matcher.rb
alphasights-integrity-0.1.9.7 lib/integrity/notifier/test/hpricot_matcher.rb
alphasights-integrity-0.1.9.8 lib/integrity/notifier/test/hpricot_matcher.rb
foca-integrity-0.1.9.1 lib/integrity/notifier/test/hpricot_matcher.rb
foca-integrity-0.1.9.2 lib/integrity/notifier/test/hpricot_matcher.rb
foca-integrity-0.1.9.3 lib/integrity/notifier/test/hpricot_matcher.rb
gforces-integrity-0.1.9.3 lib/integrity/notifier/test/hpricot_matcher.rb
gforces-integrity-0.1.9.4 lib/integrity/notifier/test/hpricot_matcher.rb
imbriaco-integrity-0.1.9.2.1 lib/integrity/notifier/test/hpricot_matcher.rb
imbriaco-integrity-0.1.9.2 lib/integrity/notifier/test/hpricot_matcher.rb
integrity-integrity-0.1.10 lib/integrity/notifier/test/hpricot_matcher.rb
integrity-integrity-0.1.9.3 lib/integrity/notifier/test/hpricot_matcher.rb
integrity-0.1.11 lib/integrity/notifier/test/hpricot_matcher.rb
integrity-0.1.10 lib/integrity/notifier/test/hpricot_matcher.rb
integrity-0.1.9.1 lib/integrity/notifier/test/hpricot_matcher.rb
integrity-0.1.9.3 lib/integrity/notifier/test/hpricot_matcher.rb