kaca 0.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/kaca +1 -1
  3. data/lib/kaca.rb +51 -14
  4. metadata +30 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c9ee60c27cd58885a11de25a5a7ba0836ee7c4d
4
- data.tar.gz: 81a0865ee003842b03f93bba90d3abf75b01284e
3
+ metadata.gz: e157ae52e4bab357e18b156c1770db9503e8bc39
4
+ data.tar.gz: 4e5d1fd71492f1522f8d9ddc2a2cd36dec62c2b4
5
5
  SHA512:
6
- metadata.gz: 03626f2f990da57f6ee202ebd88d2bc008993e721f46c1b18b991ca158058224617e290105e2ba9516cfbcd9ceeaa879fde9e924ddc4a979232261ead7f853d9
7
- data.tar.gz: b40924bb5d2a2636042cccb1975e923a2eec70618d7664f3b31f5e9c877c87ea62e9104b3053fd229c121d88248631320bc9ba178b4f4f62b02d4fb6f6fa2cb7
6
+ metadata.gz: a9466b6c31177f25fe13a125c4fc04c8f020ab5dd04a14ef2a62ef6e0aa3f0d5a7b6f69770fb8c55411f8ed8d1f4da4aa80ea51f91c239c93059ee60aba176ab
7
+ data.tar.gz: 71be9de7c7dcc02f672a22e413df0e599a9434ad73cea029bc3609401bcac98fc0794afc2a220def7d14d1c8e98d71176a1a1fd4412833d11dcbd62034fbbb99
data/bin/kaca CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'kaca'
4
4
 
5
- Kaca.new(ARGV)
5
+ Kaca.new
data/lib/kaca.rb CHANGED
@@ -3,43 +3,80 @@ require 'net/http'
3
3
  require 'json'
4
4
 
5
5
  class Kaca
6
- def initialize(opts)
6
+ def initialize(opts = ARGV)
7
7
  urls = {
8
- altin: 'http://www.doviz.com/api/v1/golds/all/latest',
9
- doviz: 'http://www.doviz.com/api/v1/currencies/all/latest'
8
+ altin: 'http://www.doviz.com/api/v1/golds/all/latest',
9
+ doviz: 'http://www.doviz.com/api/v1/currencies/all/latest',
10
+ bitcoin: 'https://blockchain.info/tr/ticker'
10
11
  }
11
12
 
13
+ if is_number? opts[0]
14
+ ne = opts[1]
15
+ nekadar = opts[0]
16
+ islem = opts[2]
17
+ else
18
+ ne = opts[0]
19
+ nekadar = nil
20
+ islem = opts[1]
21
+ end
22
+
12
23
  altinlar = %w(ceyrek-altin yarim-altin tam-altin cumhuriyet-altini ata-altin besli-altin gumus)
13
24
  birimler = %w(amerikan-dolari euro sterlin isvicre-frangi rus-rublesi japon-yeni)
14
- ne = FuzzyMatch.new(altinlar + birimler).find(opts[0].downcase)
25
+ bitcoin = %w(bitcoin coin)
26
+ ne = FuzzyMatch.new(altinlar + birimler + bitcoin).find(ne.downcase)
15
27
  url = if altinlar.include? ne
16
28
  urls[:altin]
29
+ elsif bitcoin.include? ne
30
+ urls[:bitcoin]
17
31
  else
18
32
  urls[:doviz]
19
33
  end
20
34
 
21
- islem = if FuzzyMatch.new(%w(almak alabilirim alırım)).find(opts[1])
35
+ islem = if ['alabilirim', 'alırım', 'alirim', 'bulurum'].include? islem
22
36
  'selling'
23
37
  else
24
38
  'buying'
25
39
  end
26
40
 
27
- getir(url, ne, islem)
41
+ islem = islem[0..-4] if ne == 'bitcoin'
42
+
43
+ getir(url, ne, nekadar, islem)
44
+ rescue => e
45
+ puts "Anlarken Errör olustu: #{e}"
46
+ end
47
+
48
+ def getir(url, ne, nekadar, islem)
49
+ result = get url
50
+
51
+ if ne == 'bitcoin'
52
+ aranan = 'bitcoin'
53
+ dolar = get('http://www.doviz.com/api/v1/currencies/all/latest').select { |r| r['name'] == 'amerikan-dolari' }.first
54
+ try = (result['USD'][islem] * dolar['selling']).to_f.round(2)
55
+ else
56
+ aranan = result.select { |r| r['name'] == ne }.first
57
+ try = aranan[islem].to_f.round(2)
58
+ aranan = aranan['full_name'].downcase
59
+ end
60
+ try = try * nekadar.to_i unless nekadar.nil?
61
+
62
+ sonuc = "#{try} TRY e #{aranan} #{islem == 'buying' ? 'satabilirsin' : 'alabilirsin'}."
63
+ puts sonuc
28
64
  rescue => e
29
- puts "Errör: #{e}"
65
+ puts "Getirirken Errör olustu: #{e}"
30
66
  end
31
67
 
32
- def getir(url, ne, islem)
68
+ def get url
33
69
  uri = URI.parse(url)
34
70
  http = Net::HTTP.new(uri.host)
35
71
  req = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json')
36
72
  res = http.request(req)
37
73
  result = JSON.parse(res.body)
38
74
 
39
- aranan = result.select { |r| r['name'] == ne }.first
40
- sonuc = "Bugün #{aranan['full_name'].downcase!} #{aranan[islem].to_f.round(2)} TRY e #{islem == 'buying' ? 'satabilirsin' : 'alabilirsin'}."
41
- puts sonuc
42
- rescue => e
43
- puts "Errör: #{e}"
75
+ return result
76
+ end
77
+
78
+ # Ilk parametre string fakat numeric mi bakmak icin
79
+ def is_number? string
80
+ true if Float(string) rescue false
44
81
  end
45
- end
82
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kaca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murat Bastas
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: fuzzy_match
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
27
55
  description: Kaça altın alırım? Kaça dolar satarım? Terminal üzerinden döviz hesabı
28
56
  yapabileceğiniz bir uygulama.
29
57
  email:
@@ -55,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
83
  version: '0'
56
84
  requirements: []
57
85
  rubyforge_project:
58
- rubygems_version: 2.6.12
86
+ rubygems_version: 2.6.8
59
87
  signing_key:
60
88
  specification_version: 4
61
89
  summary: Kaca alır satarım?