coinpare 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc5acc59ac68bf078d8aed7c0cd936f16fda6db021bc8f14559fae43f7bc7efb
4
- data.tar.gz: d6fda12725def1b6dbb210a15503f8d514ef08b96c52b53298cc6f0bb8ddd8ca
3
+ metadata.gz: 95d8580cc429e071a026b03263fb52cb17560486c3627867e432772285211c8a
4
+ data.tar.gz: b2aba6a81e5827730fe124326f7cc3ca9e5b75dd6223d884f4aa22a217175173
5
5
  SHA512:
6
- metadata.gz: c3a7e96d6577e227da747c29d64be46ccb6147c1a87e133ae03860de1d9c2700af9ce36f62197277a8fa0957decf8572c4fd83aea7e28d646f00354949bf6068
7
- data.tar.gz: 76675509059502f630f91ae51755981fb11a47162743b874dd58faa3b219c86fc6f043556eb257de22d1287336080f2e77c0e5318f3cb530e6f09c6bd3f04ee2
6
+ metadata.gz: 5b9a4a0dd8ff044e345d6f4cd103a19f6ce24ab73ed7bfd478e081cd3440eef5d2d276ced28851edba6e299ce2583cb6a287d252544ca27a88cc72d9ee86be25
7
+ data.tar.gz: b66f298dcaa9d28f9d9597b13c60c2fab42a66afd839b47ddb498d535bcf34a68b501e8b28690c7756d1d4d324b2fe0d2d6728f0978dcfb0c16da77a380910bc
@@ -1,5 +1,16 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.3.0] - 2020-11-09
4
+
5
+ ### Changed
6
+ * Change gemspec to only package lib files and include metadata
7
+ * Update all the tty and thor runtime dependencies
8
+ * Remove tty-color as a dependency
9
+ * Change to make tty-screen an explicit runtime dependency
10
+
11
+ ### Fixed
12
+ * Fix Ruby 2.7 keyword conversion errors
13
+
3
14
  ## [v0.2.0] - 2019-01-12
4
15
 
5
16
  ### Added
@@ -15,5 +26,6 @@
15
26
 
16
27
  * Initial implementation and release
17
28
 
29
+ [v0.3.0]: https://github.com/piotrmurach/coinpare/compare/v0.2.0...v0.3.0
18
30
  [v0.2.0]: https://github.com/piotrmurach/coinpare/compare/v0.1.0...v0.2.0
19
31
  [v0.1.0]: https://github.com/piotrmurach/coinpare/compare/v0.1.0
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- lib_path = File.expand_path('../lib', __dir__)
5
- $:.unshift(lib_path) if !$:.include?(lib_path)
6
- require 'coinpare/cli'
4
+ lib_path = File.expand_path("../lib", __dir__)
5
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
6
+ require "coinpare/cli"
7
7
 
8
- Signal.trap('INT') do
8
+ Signal.trap("INT") do
9
9
  warn("\n#{caller.join("\n")}: interrupted")
10
10
  exit(1)
11
11
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'pastel'
5
- require 'tty-font'
3
+ require "thor"
4
+ require "pastel"
5
+ require "tty-font"
6
6
 
7
7
  module Coinpare
8
8
  # Handle the application command line parsing
@@ -14,16 +14,17 @@ module Coinpare
14
14
  Error = Class.new(StandardError)
15
15
 
16
16
  def help(*args)
17
- font = TTY::Font.new(:standard)
18
- pastel = Pastel.new(enabled: !options['no-color'])
17
+ font = TTY::Font.new(:standard)
18
+ pastel = Pastel.new(enabled: !options["no-color"])
19
19
  puts pastel.yellow(font.write("Coinpare"))
20
20
  super
21
21
  end
22
22
 
23
23
  class_option :"no-color", type: :boolean, default: false,
24
- desc: 'Disable colorization in output'
24
+ desc: "Disable colorization in output"
25
25
 
26
- desc 'coins NAMES...', 'Get all the current trading data for the coin names...'
26
+ desc "coins NAMES...", "Get all the current trading data for the " \
27
+ "coin names..."
27
28
  long_desc <<-DESC
28
29
  Get all the current trading info (price, vol, open, high, low etc)
29
30
  of any list of cryptocurrencies in any other currency that you need.
@@ -39,31 +40,33 @@ module Coinpare
39
40
 
40
41
  > $ coinpare coins BTC ETH --exchange coinbase
41
42
  DESC
42
- method_option :base, aliases: '-b', type: :string, default: "USD",
43
- desc: 'The currency symbol to convert into',
44
- banner: 'CURRENCY'
45
- method_option :columns, aliases: '-c', type: :array,
46
- desc: 'Specify columns to display',
47
- banner: '0 1 2'
48
- method_option :exchange, aliases: '-e', type: :string, default: "CCCAGG",
49
- desc: 'Name of exchange',
50
- banner: 'name'
51
- method_option :help, aliases: '-h', type: :boolean,
52
- desc: 'Display usage information'
53
- method_option :top, aliases: '-t', type: :numeric, default: 10, banner: 'N',
54
- desc: "The number of top coins by total volume accross all markets in 24 hours"
55
- method_option :watch, aliases: '-w', banner: 'N',
56
- desc: 'Automatically refresh data every n seconds, default 5 sec'
43
+ method_option :base, aliases: "-b", type: :string, default: "USD",
44
+ desc: "The currency symbol to convert into",
45
+ banner: "CURRENCY"
46
+ method_option :columns, aliases: "-c", type: :array,
47
+ desc: "Specify columns to display",
48
+ banner: "0 1 2"
49
+ method_option :exchange, aliases: "-e", type: :string, default: "CCCAGG",
50
+ desc: "Name of exchange",
51
+ banner: "name"
52
+ method_option :help, aliases: "-h", type: :boolean,
53
+ desc: "Display usage information"
54
+ method_option :top, aliases: "-t", type: :numeric, default: 10, banner: "N",
55
+ desc: "The number of top coins by total volume " \
56
+ "accross all markets in 24 hours"
57
+ method_option :watch, aliases: "-w", banner: "N",
58
+ desc: "Automatically refresh data every n seconds," \
59
+ " default 5 sec"
57
60
  def coins(*names)
58
61
  if options[:help]
59
- invoke :help, ['coins']
62
+ invoke :help, ["coins"]
60
63
  else
61
- require_relative 'commands/coins'
64
+ require_relative "commands/coins"
62
65
  Coinpare::Commands::Coins.new(names, options).execute
63
66
  end
64
67
  end
65
68
 
66
- desc 'holdings', 'Keep track of all your cryptocurrency investments'
69
+ desc "holdings", "Keep track of all your cryptocurrency investments"
67
70
  long_desc <<-DESC
68
71
  Get the current trading prices and their change in value and percentage
69
72
  for all your cryptocurrency investments.
@@ -76,36 +79,40 @@ module Coinpare
76
79
 
77
80
  > $ coinpare holdings --exchange coinbase --base USD
78
81
  DESC
79
- method_option :add, aliases: '-a', type: :boolean,
80
- desc: "Add a new coin without altering any existhing holdings"
81
- method_option :base, aliases: '-b', type: :string,
82
- desc: 'The currency symbol to convert into',
83
- banner: 'CURRENCY'
82
+ method_option :add, aliases: "-a", type: :boolean,
83
+ desc: "Add a new coin without altering any " \
84
+ "existhing holdings"
85
+ method_option :base, aliases: "-b", type: :string,
86
+ desc: "The currency symbol to convert into",
87
+ banner: "CURRENCY"
84
88
  method_option :clear, type: :boolean, default: false,
85
- desc: 'Remove all coins from your existing holdings'
86
- method_option :edit, type: :string, banner: 'editor',
87
- desc: 'Open the holdings configuration file for editing in EDITOR, or the default editor if not specified.'
88
- method_option :exchange, aliases: '-e', type: :string,
89
- desc: 'Name of exchange', banner: 'NAME'
90
- method_option :help, aliases: '-h', type: :boolean,
91
- desc: 'Display usage information'
92
- method_option :pie, aliases: '-p', type: :string,
93
- desc: 'Display data in a pie chart format',
94
- banner: 'RADIUS'
89
+ desc: "Remove all coins from your existing holdings"
90
+ method_option :edit, type: :string, banner: "editor",
91
+ desc: "Open the holdings configuration file for " \
92
+ "editing in EDITOR, or the default editor " \
93
+ "if not specified."
94
+ method_option :exchange, aliases: "-e", type: :string,
95
+ desc: "Name of exchange", banner: "NAME"
96
+ method_option :help, aliases: "-h", type: :boolean,
97
+ desc: "Display usage information"
98
+ method_option :pie, aliases: "-p", type: :string,
99
+ desc: "Display data in a pie chart format",
100
+ banner: "RADIUS"
95
101
  method_option :remove, type: :boolean,
96
- desc: "Remove the given coin(s) from holdings"
97
- method_option :watch, aliases: '-w', banner: 'N',
98
- desc: 'Automatically refresh data every n seconds, default 5 sec'
102
+ desc: "Remove the given coin(s) from holdings"
103
+ method_option :watch, aliases: "-w", banner: "N",
104
+ desc: "Automatically refresh data every n seconds," \
105
+ " default 5 sec"
99
106
  def holdings(*)
100
107
  if options[:help]
101
- invoke :help, ['holdings']
108
+ invoke :help, ["holdings"]
102
109
  else
103
- require_relative 'commands/holdings'
110
+ require_relative "commands/holdings"
104
111
  Coinpare::Commands::Holdings.new(options).execute
105
112
  end
106
113
  end
107
114
 
108
- desc 'markets [NAME]', 'Get top markets by volume for a currency pair'
115
+ desc "markets [NAME]", "Get top markets by volume for a currency pair"
109
116
  long_desc <<-DESC
110
117
  Get top markets by volume for a currency pair.
111
118
 
@@ -120,32 +127,34 @@ module Coinpare
120
127
 
121
128
  > $ coinpare markets ETH -b BTC
122
129
  DESC
123
- method_option :base, aliases: '-b', type: :string, default: "USD",
124
- desc: 'The currency symbol to convert into',
125
- banner: 'CURRENCY'
126
- method_option :columns, aliases: '-c', type: :array,
127
- desc: 'Specify columns to display',
128
- banner: '0 1 2'
129
- method_option :help, aliases: '-h', type: :boolean,
130
- desc: 'Display usage information'
131
- method_option :top, aliases: '-t', type: :numeric, default: 10,
132
- desc: "The number of top exchanges by total volume in 24 hours"
133
- method_option :watch, aliases: '-w', banner: 'N',
134
- desc: 'Automatically refresh data every n seconds, default 5 sec'
135
- def markets(name = 'BTC')
130
+ method_option :base, aliases: "-b", type: :string, default: "USD",
131
+ desc: "The currency symbol to convert into",
132
+ banner: "CURRENCY"
133
+ method_option :columns, aliases: "-c", type: :array,
134
+ desc: "Specify columns to display",
135
+ banner: "0 1 2"
136
+ method_option :help, aliases: "-h", type: :boolean,
137
+ desc: "Display usage information"
138
+ method_option :top, aliases: "-t", type: :numeric, default: 10,
139
+ desc: "The number of top exchanges by total volume " \
140
+ "in 24 hours"
141
+ method_option :watch, aliases: "-w", banner: "N",
142
+ desc: "Automatically refresh data every n seconds," \
143
+ " default 5 sec"
144
+ def markets(name = "BTC")
136
145
  if options[:help]
137
- invoke :help, ['markets']
146
+ invoke :help, ["markets"]
138
147
  else
139
- require_relative 'commands/markets'
148
+ require_relative "commands/markets"
140
149
  Coinpare::Commands::Markets.new(name, options).execute
141
150
  end
142
151
  end
143
152
 
144
- desc 'version', 'coinpare version'
153
+ desc "version", "coinpare version"
145
154
  def version
146
- require_relative 'version'
155
+ require_relative "version"
147
156
  puts "v#{Coinpare::VERSION}"
148
157
  end
149
- map %w(--version -v) => :version
158
+ map %w[--version -v] => :version
150
159
  end
151
160
  end
@@ -3,22 +3,22 @@
3
3
  module Coinpare
4
4
  class Command
5
5
  SYMBOLS = {
6
- down_arrow: '',
7
- up_arrow: ''
6
+ down_arrow: "",
7
+ up_arrow: ""
8
8
  }.freeze
9
9
 
10
10
  # The default interval for auto updating data
11
11
  DEFAULT_INTERVAL = 5
12
12
 
13
- trap('SIGINT') { exit }
13
+ trap("SIGINT") { exit }
14
14
 
15
15
  # Main configuration
16
16
  # @api public
17
17
  def config
18
18
  @config ||= begin
19
19
  config = TTY::Config.new
20
- config.filename = 'coinpare'
21
- config.extname = '.toml'
20
+ config.filename = "coinpare"
21
+ config.extname = ".toml"
22
22
  config.append_path Dir.pwd
23
23
  config.append_path Dir.home
24
24
  config
@@ -28,7 +28,7 @@ module Coinpare
28
28
  # Time for when the data was fetched
29
29
  # @api public
30
30
  def timestamp
31
- "#{Time.now.strftime("%d %B %Y")} at #{Time.now.strftime("%I:%M:%S %p %Z")}"
31
+ "#{Time.now.strftime('%d %B %Y')} at #{Time.now.strftime('%I:%M:%S %p %Z')}"
32
32
  end
33
33
 
34
34
  # The exchange, currency & time banner
@@ -43,6 +43,7 @@ module Coinpare
43
43
  # @api public
44
44
  def pick_arrow(change)
45
45
  return if change.zero?
46
+
46
47
  change > 0 ? SYMBOLS[:up_arrow] : SYMBOLS[:down_arrow]
47
48
  end
48
49
 
@@ -52,6 +53,7 @@ module Coinpare
52
53
 
53
54
  def pick_color(change)
54
55
  return :none if change.zero?
56
+
55
57
  change > 0 ? :green : :red
56
58
  end
57
59
 
@@ -64,29 +66,30 @@ module Coinpare
64
66
  end
65
67
 
66
68
  def shorten_currency(value)
67
- if value > 10 ** 9
68
- (value / 10 ** 9).to_f.round(2).to_s + ' B'
69
- elsif value > 10 ** 6
70
- (value / 10 ** 6).to_f.round(2).to_s + ' M'
69
+ if value > 10**9
70
+ "#{(value / 10**9).to_f.round(2)} B"
71
+ elsif value > 10**6
72
+ "#{(value / 10**6).to_f.round(2)} M"
71
73
  else
72
74
  value
73
75
  end
74
76
  end
75
77
 
76
78
  def precision(value, decimals = 2)
77
- part = value.to_s.split('.')[1]
79
+ part = value.to_s.split(".")[1]
78
80
  return 0 if part.nil?
81
+
79
82
  value.between?(0, 1) ? (part.index(/[^0]/) + decimals) : decimals
80
83
  end
81
84
 
82
85
  def round_to(value, prec = nil)
83
86
  prec = precision(value) if prec.nil?
84
- "%.#{prec}f" % value
87
+ format("%.#{prec}f", value)
85
88
  end
86
89
 
87
90
  def number_to_currency(value)
88
- whole, part = value.to_s.split('.')
89
- part = '.' + part unless part.nil?
91
+ whole, part = value.to_s.split(".")
92
+ part = "." + part unless part.nil?
90
93
  "#{whole.gsub(/(\d)(?=(\d{3})+(?!\d))/, '\\1,')}#{part}"
91
94
  end
92
95
 
@@ -106,7 +109,7 @@ module Coinpare
106
109
  #
107
110
  # @api public
108
111
  def cursor
109
- require 'tty-cursor'
112
+ require "tty-cursor"
110
113
  TTY::Cursor
111
114
  end
112
115
 
@@ -116,7 +119,7 @@ module Coinpare
116
119
  #
117
120
  # @api public
118
121
  def editor
119
- require 'tty-editor'
122
+ require "tty-editor"
120
123
  TTY::Editor
121
124
  end
122
125
 
@@ -126,7 +129,7 @@ module Coinpare
126
129
  #
127
130
  # @api public
128
131
  def screen
129
- require 'tty-screen'
132
+ require "tty-screen"
130
133
  TTY::Screen
131
134
  end
132
135
  end # Command
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pastel'
4
- require 'tty-pager'
5
- require 'tty-spinner'
6
- require 'tty-table'
7
- require 'timers'
3
+ require "pastel"
4
+ require "tty-pager"
5
+ require "tty-spinner"
6
+ require "tty-table"
7
+ require "timers"
8
8
 
9
- require_relative '../command'
10
- require_relative '../fetcher'
9
+ require_relative "../command"
10
+ require_relative "../fetcher"
11
11
 
12
12
  module Coinpare
13
13
  module Commands
@@ -17,7 +17,7 @@ module Coinpare
17
17
  @options = options
18
18
  @pastel = Pastel.new
19
19
  @timers = Timers::Group.new
20
- @spinner = TTY::Spinner.new(':spinner Fetching data...',
20
+ @spinner = TTY::Spinner.new(":spinner Fetching data...",
21
21
  format: :dots, clear: true)
22
22
  end
23
23
 
@@ -25,9 +25,9 @@ module Coinpare
25
25
  pager = TTY::Pager.new(output: output)
26
26
  @spinner.auto_spin
27
27
 
28
- if @options['watch']
28
+ if @options["watch"]
29
29
  output.print cursor.hide
30
- interval = @options['watch'].to_f > 0 ? @options['watch'].to_f : DEFAULT_INTERVAL
30
+ interval = @options["watch"].to_f > 0 ? @options["watch"].to_f : DEFAULT_INTERVAL
31
31
  @timers.now_and_every(interval) { display_coins(output, pager) }
32
32
  loop { @timers.wait }
33
33
  else
@@ -35,7 +35,7 @@ module Coinpare
35
35
  end
36
36
  ensure
37
37
  @spinner.stop
38
- if @options['watch']
38
+ if @options["watch"]
39
39
  @timers.cancel
40
40
  output.print cursor.clear_screen_down
41
41
  output.print cursor.show
@@ -48,10 +48,11 @@ module Coinpare
48
48
  if @names.empty? # no coins provided
49
49
  @names = setup_top_coins
50
50
  end
51
- response = Fetcher.fetch_prices(@names.map(&:upcase).join(','),
52
- @options['base'].upcase, @options)
51
+ response = Fetcher.fetch_prices(@names.map(&:upcase).join(","),
52
+ @options["base"].upcase, @options)
53
53
  return unless response
54
- table = setup_table(response['RAW'], response['DISPLAY'])
54
+
55
+ table = setup_table(response["RAW"], response["DISPLAY"])
55
56
  @spinner.stop
56
57
 
57
58
  lines = banner(@options).lines.size + 1 + table.rows_size + 3
@@ -59,9 +60,9 @@ module Coinpare
59
60
  end
60
61
 
61
62
  def clear_output(output, lines)
62
- output.print cursor.clear_screen_down if @options['watch']
63
+ output.print cursor.clear_screen_down if @options["watch"]
63
64
  yield if block_given?
64
- output.print cursor.up(lines) if @options['watch']
65
+ output.print cursor.up(lines) if @options["watch"]
65
66
  end
66
67
 
67
68
  def print_results(table, output, pager)
@@ -77,41 +78,44 @@ module Coinpare
77
78
  end
78
79
 
79
80
  def setup_top_coins
80
- response = Fetcher.fetch_top_coins_by_volume(@options['base'].upcase,
81
+ response = Fetcher.fetch_top_coins_by_volume(@options["base"].upcase,
81
82
  @options)
82
83
  return unless response
83
- response['Data'].map { |coin| coin['CoinInfo']['Name'] }[0...@options['top']]
84
+
85
+ response["Data"].map { |coin| coin["CoinInfo"]["Name"] }[0...@options["top"]]
84
86
  end
85
87
 
86
88
  def setup_table(raw_data, display_data)
87
89
  table = TTY::Table.new(header: [
88
- { value: 'Coin', alignment: :left },
89
- 'Price',
90
- 'Chg. 24H',
91
- 'Chg.% 24H',
92
- 'Open 24H',
93
- 'High 24H',
94
- 'Low 24H',
95
- 'Direct Vol. 24H',
96
- 'Total Vol. 24H',
97
- 'Market Cap'
90
+ { value: "Coin", alignment: :left },
91
+ "Price",
92
+ "Chg. 24H",
93
+ "Chg.% 24H",
94
+ "Open 24H",
95
+ "High 24H",
96
+ "Low 24H",
97
+ "Direct Vol. 24H",
98
+ "Total Vol. 24H",
99
+ "Market Cap"
98
100
  ])
99
101
 
100
102
  @names.each do |name|
101
- coin_data = display_data[name.upcase][@options['base'].upcase]
102
- coin_raw_data = raw_data[name.upcase][@options['base'].upcase]
103
- change24h = coin_raw_data['CHANGE24HOUR']
103
+ coin_data = display_data[name.upcase][@options["base"].upcase]
104
+ coin_raw_data = raw_data[name.upcase][@options["base"].upcase]
105
+ change24h = coin_raw_data["CHANGE24HOUR"]
104
106
  coin_details = [
105
107
  { value: add_color(name.upcase, :yellow), alignment: :left },
106
- add_color(coin_data['PRICE'], pick_color(change24h)),
107
- add_color("#{pick_arrow(change24h)} #{coin_data['CHANGE24HOUR']}", pick_color(change24h)),
108
- add_color("#{pick_arrow(change24h)} #{coin_data['CHANGEPCT24HOUR']}%", pick_color(change24h)),
109
- coin_data['OPEN24HOUR'],
110
- coin_data['HIGH24HOUR'],
111
- coin_data['LOW24HOUR'],
112
- coin_data['VOLUME24HOURTO'],
113
- coin_data['TOTALVOLUME24HTO'],
114
- coin_data['MKTCAP']
108
+ add_color(coin_data["PRICE"], pick_color(change24h)),
109
+ add_color("#{pick_arrow(change24h)} #{coin_data['CHANGE24HOUR']}",
110
+ pick_color(change24h)),
111
+ add_color("#{pick_arrow(change24h)} #{coin_data['CHANGEPCT24HOUR']}%",
112
+ pick_color(change24h)),
113
+ coin_data["OPEN24HOUR"],
114
+ coin_data["HIGH24HOUR"],
115
+ coin_data["LOW24HOUR"],
116
+ coin_data["VOLUME24HOURTO"],
117
+ coin_data["TOTALVOLUME24HTO"],
118
+ coin_data["MKTCAP"]
115
119
  ]
116
120
  table << coin_details
117
121
  end