cotacao 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 404e22d51345cc015094830141c15a1aa0864d23
4
- data.tar.gz: 5081e564493f0caa30c451e61e09d7861714a2c8
3
+ metadata.gz: 1c7410bde6431d42625d32d9098af16bb0f7a644
4
+ data.tar.gz: bd145d940798a321b4e79513b38602ff602355e2
5
5
  SHA512:
6
- metadata.gz: 8a6bb3c1803e43909e67d116f502bcb1c6e02c77677b1715d4ee5de8e14d3ff167c8de7df6e49edd5e2c75fcbd349773123924f4f2c7b5802dbb927ef806b163
7
- data.tar.gz: 71335118b127b86579ad0b8dd7e646ee81e03ba414b63927804374f95dc9da84bdeacb3a5f0517ea023553f663a1e6de7605a96d33b85ad01ef79677db003433
6
+ metadata.gz: 59a5b8fe1d98a23f6491c111cf29623e9837d4c82e99c7dbb62546ffd97e617b07b1d4dbae977b3ba5c148bd387daa7d42c0c2c2adb600cd82b097b0e87d31e1
7
+ data.tar.gz: a8ad57c6a4a4b0eb09053862d118b99fbef8a7594cd35c8c3b44019b7738ae6687a535c047bbed7ad3c795bc4457e41056f94783177930749d2ade3892999ee9
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
data/Gemfile CHANGED
@@ -4,3 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'json'
7
+ gem 'httparty'
8
+ gem 'colorize'
9
+ gem 'pry'
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Cotacao
2
2
 
3
- TODO: Write a gem description
4
3
 
5
4
  ## Installation
6
5
 
@@ -20,7 +19,8 @@ Or install it yourself as:
20
19
 
21
20
  ## Usage
22
21
 
23
- TODO: Write usage instructions here
22
+ $ cotacao
23
+ #~> Dolar: R$ 3.0380 - Variação: +0.60
24
24
 
25
25
  ## Contributing
26
26
 
data/bin/cotacao CHANGED
File without changes
@@ -1,3 +1,3 @@
1
1
  module Cotacao
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/cotacao.rb CHANGED
@@ -1,18 +1,49 @@
1
1
  require "cotacao/version"
2
2
  require 'httparty'
3
3
  require 'json'
4
+ require 'colorize'
5
+ require 'pry'
4
6
 
5
7
  module Cotacao
6
8
  class Cotacao
7
9
 
8
10
  def initialize
9
- apiUrl = 'http://developers.agenciaideias.com.br/cotacoes/json'
11
+ apiUrl = 'http://developers.agenciaideias.com.br/cotacoes/json'
10
12
  response = HTTParty.get(apiUrl)
11
- @cotacoes = JSON.parse(response.body)
13
+ @data = JSON.parse(response.body)
12
14
  end
13
15
 
14
16
  def now
15
- puts "Dolar: R$ #{@cotacoes['dolar']['cotacao']} - Variação: #{@cotacoes['dolar']['variacao']}"
17
+ self.console_print('dolar', @data['dolar'], "Dolar: R$ #{@data['dolar']['cotacao']} - Variação: #{@data['dolar']['variacao']}")
18
+ self.console_print('euro', @data['euro'], "Euro: R$ #{@data['euro']['cotacao']} - Variação: #{@data['euro']['variacao']}")
19
+ self.console_print('bovespa', @data['bovespa'], "Bovespa: #{@data['bovespa']['cotacao']} - Variação: #{@data['bovespa']['variacao']}")
16
20
  end
21
+
22
+ def console_print(type, cotacao, copy)
23
+ puts '----------------------'
24
+ puts paint(copy, cotacao['variacao'].to_f)
25
+ end
26
+
27
+ def status(variation)
28
+ if variation > 0.00
29
+ return 'positive'
30
+ elsif variation == 0.00
31
+ return 'stable'
32
+ elsif variation < 0.00
33
+ return 'negative'
34
+ end
35
+ end
36
+
37
+ def paint(copy, variation)
38
+ variation_status = status(variation)
39
+ if variation_status == 'positive'
40
+ " ↑↑ #{copy} ↑↑".green
41
+ elsif variation_status == 'stable'
42
+ " ●● #{copy} ●●".yellow
43
+ elsif variation_status == 'negative'
44
+ " ↓↓ #{copy} ↓↓".red
45
+ end
46
+ end
47
+
17
48
  end
18
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotacao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Brito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-19 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler