da_coin_market_cap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 749d85d3a24bf1bbdcbded6627e24b6550176e9e0595b8be6e1d5f285250fe88
4
+ data.tar.gz: 77b00e5f7a5b4c02d13e749353497ff13ffbb3d8d14ebf9cd988b123abda3b59
5
+ SHA512:
6
+ metadata.gz: 44e25e42d2b29d3d89f1bf7d27001630a5e3428bdef4716df8410dc0ebd7a2fef09ce57b43ad38e14707ccfef0a4626490d28908639fd0383193af17f1946e17
7
+ data.tar.gz: 2c67230972da88838ea823554fe97e2f28274aa92917cc2da0a17838e0f7c754891b825e10d81fa493d01e51865ec9d622cbc97026aefa3f25b7fadc6bca2028
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "examples/now-playing-cli-gem"]
2
+ path = examples/now-playing-cli-gem
3
+ url = git@github.com:learn-co-curriculum/now-playing-cli-gem.git
data/.learn ADDED
@@ -0,0 +1,8 @@
1
+ tags:
2
+ - cli
3
+ - gem
4
+ - oo
5
+ languages:
6
+ - ruby
7
+ resources:
8
+ live_assessment: true
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,37 @@
1
+ # Contributing to Learn.co Curriculum
2
+
3
+ We're really exited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible.
4
+
5
+ ## Raising an Issue to Encourage a Contribution
6
+
7
+ If you notice a problem with the curriculum that you believe needs improvement
8
+ but you're unable to make the change yourself, you should raise a Github issue
9
+ containing a clear description of the problem. Include relevant snippets of
10
+ the content and/or screenshots if applicable. Curriculum owners regularly review
11
+ issue lists and your issue will be prioritized and addressed as appropriate.
12
+
13
+ ## Submitting a Pull Request to Suggest an Improvement
14
+
15
+ If you see an opportunity for improvement and can make the change yourself go
16
+ ahead and use a typical git workflow to make it happen:
17
+
18
+ * Fork this curriculum repository
19
+ * Make the change on your fork, with descriptive commits in the standard format
20
+ * Open a Pull Request against this repo
21
+
22
+ A curriculum owner will review your change and approve or comment on it in due
23
+ course.
24
+
25
+ # Why Contribute?
26
+
27
+ Curriculum on Learn is publicly and freely available under Learn's
28
+ [Educational Content License](https://learn.co/content-license). By
29
+ embracing an open-source contribution model, our goal is for the curriculum
30
+ on Learn to become, in time, the best educational content the world has
31
+ ever seen.
32
+
33
+ We need help from the community of Learners to maintain and improve the
34
+ educational content. Everything from fixing typos, to correcting
35
+ out-dated information, to improving exposition, to adding better examples,
36
+ to fixing tests—all contributions to making the curriculum more effective are
37
+ welcome.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ coin_market_cap (0.1.0)
5
+ nokogiri
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ method_source (0.9.0)
12
+ mini_portile2 (2.3.0)
13
+ nokogiri (1.8.1)
14
+ mini_portile2 (~> 2.3.0)
15
+ pry (0.11.3)
16
+ coderay (~> 1.1.0)
17
+ method_source (~> 0.9.0)
18
+ rake (10.4.2)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.16)
25
+ coin_market_cap!
26
+ pry
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.16.1
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ #Learn.co Educational Content License
2
+
3
+ Copyright (c) 2015 Flatiron School, Inc
4
+
5
+ The Flatiron School, Inc. owns this Educational Content. However, the Flatiron School supports the development and availability of educational materials in the public domain. Therefore, the Flatiron School grants Users of the Flatiron Educational Content set forth in this repository certain rights to reuse, build upon and share such Educational Content subject to the terms of the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). You must read carefully the terms and conditions contained in the Educational Content License as such terms govern access to and use of the Educational Content.
6
+
7
+ Flatiron School is willing to allow you access to and use of the Educational Content only on the condition that you accept all of the terms and conditions contained in the Educational Content License set forth [here](http://learn.co/content-license) (http://learn.co/content-license). By accessing and/or using the Educational Content, you are agreeing to all of the terms and conditions contained in the Educational Content License. If you do not agree to any or all of the terms of the Educational Content License, you are prohibited from accessing, reviewing or using in any way the Educational Content.
data/NOTE.md ADDED
@@ -0,0 +1,20 @@
1
+
2
+
3
+ CLI :
4
+ 1. welcome
5
+ 2. menu
6
+ 3. list coin
7
+
8
+ Scraper :
9
+ 1. scrape list of coin return object
10
+ - name
11
+ - market cap
12
+ - price
13
+ - 24h change
14
+ 2. scrape single page info
15
+ - 24h evolution
16
+ - circulating supply
17
+ - max supply
18
+ - website
19
+ - explorer
20
+ - source
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # TOP 10 Cryptocurrencies CLI
2
+
3
+ coin-market-cap gem will allow you to display the TOP 10 cryptocurrencies and display its details via CLI. Data are pulled from https://coinmarketcap.com/
4
+
5
+ ## Available Command
6
+
7
+ Use `list` to display the list of cryptocurrencies.
8
+ Use `exit` to exit the CLI.
9
+
10
+ ### Installing
11
+
12
+ To install the gem type:
13
+
14
+ ```
15
+ gem install da_coin_market_cap
16
+ ```
17
+
18
+ ## Authors
19
+
20
+ * **Denis Atkesone** - [Denis](https://github.com/kheyro/)
21
+
22
+ ## License
23
+
24
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/coin_market_cap"
4
+
5
+ CoinMarketCap::CLI.new
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coin_market_cap"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "coin_market_cap/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "da_coin_market_cap"
8
+ spec.version = CoinMarketCap::VERSION
9
+ spec.authors = ["'Denis Atkesone'"]
10
+ spec.email = ["'denis.atkesone@gmail.com'"]
11
+
12
+ spec.summary = %q{List top 10 cryptocurrencies.}
13
+ spec.description = %q{List and view detailed information of the top 10 cryptocurrencies.}
14
+ spec.homepage = "http://deniscodes.com/"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "pry"
35
+
36
+ spec.add_runtime_dependency "nokogiri", "~> 1.8.1"
37
+ spec.add_runtime_dependency "colorize", "~> 0.8.1"
38
+ end
@@ -0,0 +1,59 @@
1
+ class CoinMarketCap::CLI
2
+
3
+ def initialize
4
+ puts "Welcome to the CoinMarketCap list gem!"
5
+ list_top10
6
+ user_input
7
+ end
8
+
9
+ def list_top10
10
+ puts "\nList of the TOP10 cryptocurrencies:"
11
+ @top10 = CoinMarketCap::Scraper.list
12
+ @top10.each.with_index(1) { |coin, i|
13
+ puts "#{i}. #{coin.name.upcase.colorize(:light_blue)} / #{coin.price}$ / #{coin.mcap}$ / #{color_change(coin.change)}"
14
+ }
15
+ end
16
+
17
+ def user_input
18
+ input = nil
19
+
20
+ while input != "exit"
21
+ puts "\nPlease choose a coin, display the list or exit:"
22
+ input = gets.strip.downcase
23
+
24
+ if input == "list"
25
+ list_top10
26
+ elsif input == "exit"
27
+ puts "\nBye bye, see you next time!"
28
+ break
29
+ elsif input.to_i.between?(1,10)
30
+ coin = @top10[input.to_i - 1]
31
+
32
+ if coin.website.nil?
33
+ coin = CoinMarketCap::Scraper.get_coin(coin)
34
+ end
35
+
36
+ display_detail(coin)
37
+ else
38
+ puts "Please type a number, list or exit. Try again!"
39
+ end
40
+ end
41
+ end
42
+
43
+ def display_detail(coin)
44
+ puts "\n"
45
+ puts "#{coin.name.upcase.colorize(:light_blue)}"
46
+ puts "Price: #{coin.price}"
47
+ puts "Volume: #{coin.volume}"
48
+ puts "Market Cap: #{coin.mcap}"
49
+ puts "24H Change: #{color_change(coin.change)}"
50
+ puts "Circulating Supply: #{coin.cir_supply}"
51
+ puts "Total Supply: #{coin.max_supply}"
52
+ puts "Website: #{coin.website}"
53
+ end
54
+
55
+ def color_change(number)
56
+ number = number.gsub("%", "").to_f
57
+ (number < 0) ? "#{number.to_s}%".colorize(:red) : "#{number.to_s}%".colorize(:green)
58
+ end
59
+ end
@@ -0,0 +1,19 @@
1
+ class CoinMarketCap::Coin
2
+ attr_accessor :name, :mcap, :price, :change, :url, :volume, :cir_supply, :max_supply, :website
3
+
4
+ def initialize(name, mcap, price, change, url)
5
+ @name = name
6
+ @mcap = mcap
7
+ @price = price
8
+ @change = change
9
+ @url = url
10
+ end
11
+
12
+ def self.add_attributes(coin, attributes)
13
+ coin.volume = attributes[:volume]
14
+ coin.cir_supply = attributes[:cir_supply]
15
+ coin.max_supply = attributes[:max_supply]
16
+ coin.website = attributes[:website]
17
+ coin
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ class CoinMarketCap::Scraper
2
+
3
+ def self.list
4
+ doc = Nokogiri::HTML(open("https://coinmarketcap.com/"))
5
+
6
+ doc.search("#currencies tbody tr")[0..9].map { |coin|
7
+ name = coin.search(".currency-name-container").text.strip
8
+ mcap = coin.search(".market-cap").text.strip
9
+ price = coin.search(".price").text.strip
10
+ change = coin.search(".percent-24h").text.strip
11
+ url = coin.search("a").attr('href') # works only with a tag
12
+ CoinMarketCap::Coin.new(name, mcap, price, change, "https://coinmarketcap.com#{url}")
13
+ }
14
+ end
15
+
16
+ def self.get_coin(coin)
17
+ doc = Nokogiri::HTML(open(coin.url))
18
+
19
+ # add attribute to the coin object
20
+ attributes = {
21
+ :volume => "$#{doc.search(".container .coin-summary-item:nth-child(2) .coin-summary-item-detail span:first-child span:first-child").text.strip}",
22
+ :cir_supply => doc.search(".container .coin-summary-item:nth-child(4) .coin-summary-item-detail").text.strip.gsub(/\s/, ""),
23
+ :max_supply => doc.search(".container .coin-summary-item:nth-child(5) .coin-summary-item-detail").text.strip.gsub(/\s/, ""),
24
+ :website => doc.search("ul.list-unstyled li:first-child a").attr("href") }
25
+
26
+ CoinMarketCap::Coin.add_attributes(coin, attributes)
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ module CoinMarketCap
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'colorize'
5
+ require_relative './coin_market_cap/version'
6
+ require_relative './coin_market_cap/cli'
7
+ require_relative './coin_market_cap/scraper'
8
+ require_relative './coin_market_cap/coin'
9
+
10
+ module CoinMarketCap
11
+ # Your code goes here...
12
+ end
data/spec.md ADDED
@@ -0,0 +1,6 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application : CLI interface is coded in the cli.rb, user is presented with a list of top 10 cryptocurrencies and he is asked to select one of them.
5
+ - [x] Pull data from an external source : data have been scraped from https://coinmarketcap.com/
6
+ - [x] Implement both list and detail views : the list view is the prompted at launch and the detail view is shown after selecting the coin.
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: da_coin_market_cap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Denis Atkesone'"
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.1
83
+ description: List and view detailed information of the top 10 cryptocurrencies.
84
+ email:
85
+ - "'denis.atkesone@gmail.com'"
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".gitmodules"
92
+ - ".learn"
93
+ - CONTRIBUTING.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.md
97
+ - NOTE.md
98
+ - README.md
99
+ - Rakefile
100
+ - bin/coin_market_cap
101
+ - bin/console
102
+ - bin/setup
103
+ - coin-market-cap.gemspec
104
+ - lib/coin_market_cap.rb
105
+ - lib/coin_market_cap/cli.rb
106
+ - lib/coin_market_cap/coin.rb
107
+ - lib/coin_market_cap/scraper.rb
108
+ - lib/coin_market_cap/version.rb
109
+ - spec.md
110
+ homepage: http://deniscodes.com/
111
+ licenses: []
112
+ metadata:
113
+ allowed_push_host: https://rubygems.org
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.7.4
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: List top 10 cryptocurrencies.
134
+ test_files: []