Class: CLI::Scraper
- Inherits:
-
Object
- Object
- CLI::Scraper
- Defined in:
- lib/what_is_this/Scraper.rb
Instance Attribute Summary collapse
-
#downloads ⇒ Object
Returns the value of attribute downloads.
-
#markup ⇒ Object
Returns the value of attribute markup.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name = nil, markup = nil, downloads = nil) ⇒ Scraper
constructor
A new instance of Scraper.
Constructor Details
#initialize(name = nil, markup = nil, downloads = nil) ⇒ Scraper
Returns a new instance of Scraper.
4 5 6 7 8 |
# File 'lib/what_is_this/Scraper.rb', line 4 def initialize(name = nil, markup = nil, downloads = nil) @name = name @markup = markup @downloads = downloads end |
Instance Attribute Details
#downloads ⇒ Object
Returns the value of attribute downloads.
2 3 4 |
# File 'lib/what_is_this/Scraper.rb', line 2 def downloads @downloads end |
#markup ⇒ Object
Returns the value of attribute markup.
2 3 4 |
# File 'lib/what_is_this/Scraper.rb', line 2 def markup @markup end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/what_is_this/Scraper.rb', line 2 def name @name end |
Class Method Details
.downloads ⇒ Object
18 19 20 |
# File 'lib/what_is_this/Scraper.rb', line 18 def self.downloads @doc.css('.gem__downloads').first.text.strip end |
.exact_display(instance) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/what_is_this/Scraper.rb', line 21 def self.exact_display(instance) query = instance.name.split(' ') query = query.map do |word| word.capitalize end.flatten puts "=======================================================" puts "--------#{query}--------" puts '' puts "About: #{self.markup}" puts '' puts "Downloads: #{self.downloads}" puts '' puts "---------------------------------" end |
.getData(name) ⇒ Object
10 11 12 13 14 |
# File 'lib/what_is_this/Scraper.rb', line 10 def self.getData(name) @doc = Nokogiri::HTML(open("https://rubygems.org/gems/#{name}")) instance = self.new(name, self.markup, self.downloads) exact_display(instance) end |
.markup ⇒ Object
15 16 17 |
# File 'lib/what_is_this/Scraper.rb', line 15 def self.markup @doc.css('#markup').text.strip end |