Sha256: a8312b15c448897ce2c66f73965b57a7bc555f8eac0463a556285644847f9d00
Contents?: true
Size: 677 Bytes
Versions: 1
Compression:
Stored size: 677 Bytes
Contents
require 'nokogiri' require 'open-uri' require 'pry' module WebGrep class Grep def initialize(word:,url:,file:,quite:) if file && url raise 'Should set one of params, url or file!' end if url && !url.match('http://|https://') url = "http://#{url}" end @word, @url, @file, @quite = word, url, file, quite end def grep! Nokogiri::XML(open(@url || @file)).search('[text()*=""]').select do |e| e.content .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') .match /#{@word}/ end rescue SocketError raise 'Bad url or connection!' end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
web_grep-1.1.0 | lib/web_grep/grep.rb |