Class: CryptoCompare::Scraper
- Inherits:
-
Object
- Object
- CryptoCompare::Scraper
- Defined in:
- lib/crypto_compare/scraper.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
- #get_attributes(crypto_currency, source) ⇒ Object
- #get_list(source) ⇒ Object
-
#initialize ⇒ Scraper
constructor
A new instance of Scraper.
Constructor Details
#initialize ⇒ Scraper
Returns a new instance of Scraper.
6 7 8 |
# File 'lib/crypto_compare/scraper.rb', line 6 def initialize @page = Nokogiri::HTML(open("https://coinmarketcap.com/")) end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
4 5 6 |
# File 'lib/crypto_compare/scraper.rb', line 4 def page @page end |
Instance Method Details
#get_attributes(crypto_currency, source) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/crypto_compare/scraper.rb', line 14 def get_attributes(crypto_currency, source) data = {} data["name"] = crypto_currency data["price"] = source.css("tr#id-#{crypto_currency} td.no-wrap a.price").text data["market_cap"] = source.css("tr#id-#{crypto_currency} td.market-cap").text.gsub(/\s+/, "") data["circulating_supply"] = source.css("tr#id-#{crypto_currency} td.no-wrap a[target='_blank']").text.gsub(/\s+/, " ") data["percent_change"] = source.css("tr#id-#{crypto_currency} td.percent-24h").text data end |
#get_list(source) ⇒ Object
10 11 12 |
# File 'lib/crypto_compare/scraper.rb', line 10 def get_list(source) source.css("td.currency-name a" ).enum_for(:each_with_index).collect {|crypto, index| crypto.text.downcase.gsub(" ","-") if index <= 9 }.compact end |