Class: BonjourgemParser
- Inherits:
-
Object
- Object
- BonjourgemParser
- Defined in:
- lib/parser/bonjourgem_parser.rb
Overview
Instance Method Summary collapse
- #already_covered?(gem) ⇒ Boolean
-
#initialize(opts) ⇒ BonjourgemParser
constructor
A new instance of BonjourgemParser.
- #output_result(text, bool) ⇒ Object
- #process ⇒ Object
Constructor Details
#initialize(opts) ⇒ BonjourgemParser
Returns a new instance of BonjourgemParser.
5 6 7 8 |
# File 'lib/parser/bonjourgem_parser.rb', line 5 def initialize(opts) @file = opts[:l] || false @gem = opts[:g] || false end |
Instance Method Details
#already_covered?(gem) ⇒ Boolean
36 37 38 39 40 |
# File 'lib/parser/bonjourgem_parser.rb', line 36 def already_covered?(gem) gem_encode = URI::encode(gem) doc = Nokogiri::HTML(open("https://www.google.fr/search?q=#{gem_encode}+site%3Abonjourgem.com")) output_result(gem, !doc.css('h3.r a').empty?) end |
#output_result(text, bool) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/parser/bonjourgem_parser.rb', line 28 def output_result(text, bool) if bool puts "#{text} : already covered !".red else puts "#{text} : not covered atm".green end end |
#process ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/parser/bonjourgem_parser.rb', line 10 def process if @file if (File.exists?(@file)) f = File.open(@file, 'r') f.each_line do |line| line.strip! next if line.empty? already_covered?(line).inspect end else puts "There is no file here".red exit end elsif @gem already_covered?(@gem).inspect end end |