Skip to content

Commit

Permalink
Tablify coin list with formatador
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Bates committed Feb 11, 2018
1 parent ac27fba commit 50c872c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: .
specs:
hodlmoon (0.1.0)
formatador
httparty
thor

Expand All @@ -15,6 +16,7 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
formatador (0.2.5)
hashdiff (0.3.0)
httparty (0.15.7)
multi_xml (>= 0.5.2)
Expand Down
2 changes: 2 additions & 0 deletions hodlmoon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.5.0'

spec.add_dependency 'formatador'
spec.add_dependency 'httparty'
spec.add_dependency 'thor'

Expand Down
5 changes: 3 additions & 2 deletions lib/hodlmoon/cli.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'thor'
require 'hodlmoon/client/retrieve_price'
require 'hodlmoon/client/retrieve_list'
require 'hodlmoon/table'

module Hodlmoon
class Cli < Thor
Expand All @@ -22,9 +23,9 @@ def price(coin, currency = 'gbp')
end

desc 'list LIMIT CURRENCY', 'get LIMIT of top coins in CURRENCY(optional)'
def list(limit = 10, currency = 'gbp')
def list(limit = 5, currency = 'gbp')
info = Hodlmoon::Client::RetrieveList.call(limit, currency)
puts info
Hodlmoon::Table.build(info)
end
end
end
2 changes: 1 addition & 1 deletion lib/hodlmoon/client/retrieve_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Hodlmoon
module Client
class RetrievePrice < Base
def self.call(coin, currency)
new(coin: coin, currency: currency).retrieve_price
new(coin: coin, currency: currency).call
end

def call
Expand Down
27 changes: 27 additions & 0 deletions lib/hodlmoon/table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'formatador'

module Hodlmoon
class Table
def self.build(info)
new(info).build
end

def initialize(info)
@info = info
end

def build
Formatador.display_table(filtered_info, headers)
end

private

def filtered_info
@info.map { |coin| coin.slice(*headers) }
end

def headers
['name', 'symbol', 'price_gbp', 'market_cap_gbp', 'percent_change_1h', 'percent_change_24h', 'percent_change_7d']
end
end
end

0 comments on commit 50c872c

Please sign in to comment.