coin_market_cap 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OGQ5Njg2ZjIxNGEzOTQwOTgyMjgxMWIxY2I1YmExOTRjNjgxYWRiNg==
5
- data.tar.gz: !binary |-
6
- MjM2ZTc5OGViNWRmYzNjYjRkOWQyZjJmMzhlZGYwNGI0NjhmYWRmYw==
2
+ SHA256:
3
+ metadata.gz: bbc1bc5d02312fcdae8a99261513a8231b26af24035e1d1adcc25c193e199dad
4
+ data.tar.gz: d582a6f83f28b2c7741e1bcd2112565028fd3b1f134ccaadeeac4afe11fc7c4a
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YjVmY2YwOGM0NzY2ZTU2YTM2ZjExMWVjMTA3N2Y1ZDc3MDJmMTIwZDllZjA1
10
- NTk0NjVjMGVlODVhNjUxNjlmNTYxYzNjMGZjYTA4MjY2Y2QyZmEwOTljZDM3
11
- ODdiYjgxYTdkZDZhYmY5MTI4MTIyNTMzMmFhOTMxNDNkOWU0ODg=
12
- data.tar.gz: !binary |-
13
- YmRhYWU4ODIxNDZiZGMyZjY0YzExOTM1NDIzMzU4NjUyNzc1NDMxMmI1MTAy
14
- OTRhNGU1ZGNmNmY0OTJmOWRkMmE5NDczNzBhNGNiNGQzZDM3YzgxMjliOTUy
15
- M2IwYmM3ODcxYTcxMWU0YTIwNjJjMGM0ZDhkMGYxZjYxNjQ0MDQ=
6
+ metadata.gz: c58bbedf434fa55309faa5437427a9fd02522a6b194bef9cc31e6aecaf965eb3dcc67e859fb5be2b1256c25174369bea88eb9feeb3aa354f0ebed96eb71d4233
7
+ data.tar.gz: 3feace823fbded85cdd0e50ba5bd5be93af4426c6ecaea53724780f6d96a60db0bd3cd59c385c0b96b8bdf3847b1c8415583c44a7eeca9a702afebf7cb87fdc0
data/README.md CHANGED
@@ -25,9 +25,6 @@ Or install it yourself as:
25
25
  bitcoin.price
26
26
  #=> 847.63
27
27
 
28
- bitcoin.price_btc
29
- #=> 1.00
30
-
31
28
  ## Contributing
32
29
 
33
30
  1. Fork it ( http://github.com/<my-github-username>/coin_market_cap/fork )
@@ -1,44 +1,32 @@
1
1
  module CoinMarketCap
2
2
 
3
+ COIN_MARKET_CAP_URL = "https://coinmarketcap.com/"
4
+
3
5
  # Coin class
4
6
  class Coin
5
7
  attr_accessor :coin
6
8
 
7
9
  def initialize(coin)
8
10
  @coin = coin.downcase
9
- end
10
-
11
- def sample_message
12
- "Hello, World!"
11
+ @currencies = fetch_coin_prices
13
12
  end
14
13
 
15
14
  def price
16
- coin_price = fetch_coin_price(@coin, 'USD')
17
- coin_price
18
- end
19
-
20
- def price_btc
21
- coin_price = fetch_coin_price(@coin, 'BTC')
22
- coin_price
15
+ @currencies[@coin]
23
16
  end
24
17
 
25
18
  private
26
19
 
27
- def fetch_coin_price(coin, price_type)
28
- doc = Nokogiri::HTML(open("http://www.coinmarketcap.com"))
20
+ def fetch_coin_prices
21
+ doc = Nokogiri::HTML(open(COIN_MARKET_CAP_URL))
29
22
  currencies = {}
30
23
 
31
24
  doc.css("#currencies tbody tr").each do |coin|
32
- currency = coin.css(".no-wrap.currency-name a").text.downcase
33
- if price_type == 'USD'
34
- price = coin.css("td[4] a").attribute('data-usd').value.to_f
35
- else
36
- price = coin.css("td[4] a").attribute('data-btc').value.to_f
37
- end
25
+ currency = coin.css("td a.currency-name-container").text.downcase.gsub(" ", "_")
26
+ price = coin.css("td .price").attribute('data-usd').value.to_f
38
27
  currencies[currency] = price
39
28
  end
40
-
41
- currencies[coin]
29
+ currencies
42
30
  end
43
31
 
44
32
  end
@@ -1,3 +1,3 @@
1
1
  module CoinMarketCap
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,22 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CoinMarketCap do
4
-
5
- it "should display sample message" do
6
- sample_message = CoinMarketCap::Coin.new('bitcoin').sample_message
7
- expect(sample_message).to eq("Hello, World!")
8
- end
9
-
10
- it "should return price of the coin" do
4
+ it "should return price of bitcoin" do
11
5
  coin = CoinMarketCap::Coin.new('bitcoin')
12
6
  expect(coin.price).to be_kind_of(Float)
13
- coin = CoinMarketCap::Coin.new('litecoin')
14
- expect(coin.price).to be_kind_of(Float)
15
7
  end
16
8
 
17
- it "should return price of coin in BTC" do
18
- coin = CoinMarketCap::Coin.new('bitcoin')
19
- expect(coin.price_btc).to eq(1.00)
9
+ it "should return price of litecoin" do
10
+ coin = CoinMarketCap::Coin.new('litecoin')
11
+ expect(coin.price).to be_kind_of(Float)
20
12
  end
21
-
22
13
  end
metadata CHANGED
@@ -1,87 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coin_market_cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinay Solanki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-14 00:00:00.000000000 Z
11
+ date: 2019-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
- - - ! '>='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: 1.6.1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ~>
27
+ - - "~>"
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.6'
30
- - - ! '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: 1.6.1
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '1.5'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ~>
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.5'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ~>
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '10.1'
54
- - - ! '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: 10.1.1
57
57
  type: :development
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ~>
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
63
  version: '10.1'
64
- - - ! '>='
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: 10.1.1
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rspec
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ~>
71
+ - - "~>"
72
72
  - !ruby/object:Gem::Version
73
73
  version: '2.14'
74
- - - ! '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 2.14.1
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '2.14'
84
- - - ! '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: 2.14.1
87
87
  description: Ruby gem to fetch Crypto currency prices from Coin Market Cap
@@ -91,7 +91,7 @@ executables: []
91
91
  extensions: []
92
92
  extra_rdoc_files: []
93
93
  files:
94
- - .gitignore
94
+ - ".gitignore"
95
95
  - Gemfile
96
96
  - LICENSE.txt
97
97
  - README.md
@@ -112,17 +112,16 @@ require_paths:
112
112
  - lib
113
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ! '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - ! '>='
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.2.1
124
+ rubygems_version: 3.0.2
126
125
  signing_key:
127
126
  specification_version: 4
128
127
  summary: Coin Market Cap gem