Sha256: fcde269e92c8c4c2264115739534282e6416c92bb32b40f49bd077fbd5cfaecb

Contents?: true

Size: 769 Bytes

Versions: 1

Compression:

Stored size: 769 Bytes

Contents

require 'nokogiri'
module Trackman
  module Urls
    module HtmlParser
      include CssParser
      
      def parse html
        doc = Nokogiri::HTML(html)
        img(doc) + js(doc) + css(doc) + parse_css(html)
      end
      
      def img doc
        imgs = refine(doc.css('img'), 'src')
        icons = refine(doc.xpath('//link[@rel="icon"]'), 'href')
        
        imgs + icons
      end
      
      def js doc
        refine(doc.xpath('//script'), 'src')
      end
      def css doc
        refine(doc.xpath('//link[@type="text/css"]'), 'href')
      end

      def refine(paths, node)
        temp = paths.map{|n| n[node].to_s.gsub(/\?[^\?]*$/, '') }
        temp.select{|n| n && n =~ /\w/ && n.internal_path? && !n.embedded? }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trackman-0.6.7 lib/trackman/urls/html_parser.rb