Sha256: 2e16b0c5fafa976c6d0d1ac09f3b0a1b13e3da066c55eaed162b3ea838f28312

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

class CryptoPrice::Scraper
  def self.scrape_coinmarketcap
    doc = Nokogiri::HTML(open("https://coinmarketcap.com"))
    doc.css("a.price").text.split("$").select{ |k| k.length > 0  }
  end

  def self.scrape_coinlib
    doc = Nokogiri::HTML(open("https://coinlib.io/coins"))
    prices = self.scrape_coinmarketcap
    names = doc.css("div.tbl-currency").text.split("\n").select{ |k| !k.include?("[") && k.length > 0  }
    symbols = doc.css("span.tbl-coin-abbrev").text.gsub("]", "").split("[").select{ |k| k.length > 0  }
    changes = doc.css("span.tbl-price.pr-change").text.split("%").select{ |k| k.length > 0  }
    marketcaps = doc.css("span.mob-info-value").text.split("$").select{ |k| k.length > 0  }
    #binding.pry
    index = 0
    while index < names.length && index < symbols.length 
      symbol = symbols[index]
      name = names[index]
      price = prices[index]
      change = changes[index]
      marketcap = marketcaps[index]
      CryptoPrice::Coin.new(symbol, name, price,change, marketcap)
      index += 1
    end
    CryptoPrice::Coin.all
  end 
end 

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
crypto_price-0.1.2 lib/crypto_price/scraper.rb
crypto_price-0.1.1 lib/crypto_price/scraper.rb
crypto_price-0.1.0 lib/crypto_price/scraper.rb