Sha256: f57bffaaebcafb6b6a377cbcd5c171570abb208cad2710a0d0d407fde1566507

Contents?: true

Size: 845 Bytes

Versions: 1

Compression:

Stored size: 845 Bytes

Contents

require_relative '../crypto_compare.rb'

class CryptoCompare::Scraper
	attr_accessor :page

	def initialize
		@page = Nokogiri::HTML(open("https://coinmarketcap.com/"))
	end

	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

	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 

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
crypto_compare-0.1.13 lib/crypto_compare/scraper.rb