kaca 0.0.1 → 0.1.0

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 +2 -1
  3. data/lib/kaca.rb +27 -26
  4. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37bef440fd7f084d3b0f6914c341a9fe902ff020
4
- data.tar.gz: 1d2ae65c333b64872f7309c2adcb5e30785af9b9
3
+ metadata.gz: 2c9ee60c27cd58885a11de25a5a7ba0836ee7c4d
4
+ data.tar.gz: 81a0865ee003842b03f93bba90d3abf75b01284e
5
5
  SHA512:
6
- metadata.gz: a4eb778d8e1ef2509ff040bfbe66b34fbad6d49aab92959a58abd5594dfd3d6dfd87b741ab1fce6357597e6c49a2f715de5dff8186a50eb7cf28ce7a38355198
7
- data.tar.gz: 169c57db4650b40fa241486586eb1ddff41c589ba82b9791d72c06d842b3d65fd7c4f521397893511dec53e10c0bccd7fefa449286bb4b9026da2f3e8e2e93a0
6
+ metadata.gz: 03626f2f990da57f6ee202ebd88d2bc008993e721f46c1b18b991ca158058224617e290105e2ba9516cfbcd9ceeaa879fde9e924ddc4a979232261ead7f853d9
7
+ data.tar.gz: b40924bb5d2a2636042cccb1975e923a2eec70618d7664f3b31f5e9c877c87ea62e9104b3053fd229c121d88248631320bc9ba178b4f4f62b02d4fb6f6fa2cb7
data/bin/kaca CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'kaca'
4
- Kaca.new(ARGV[0], ARGV[1])
4
+
5
+ Kaca.new(ARGV)
data/lib/kaca.rb CHANGED
@@ -1,34 +1,35 @@
1
+ require 'fuzzy_match'
1
2
  require 'net/http'
2
3
  require 'json'
3
4
 
4
5
  class Kaca
5
- def initialize(ne, islem)
6
- puts "Kaça #{ne} #{islem}?"
7
- urls = {
8
- altin: 'http://www.doviz.com/api/v1/golds/all/latest',
9
- doviz: 'http://www.doviz.com/api/v1/currencies/all/latest'
10
- }
11
-
12
- ne = ne.downcase.gsub(/(?<=\w)/, '').gsub(' ', '-')
13
- islem = islem.downcase.gsub(/(?<=\w)/, '').gsub(' ', '-')
14
-
15
-
16
- url = if ne =~ /altin|altın|ceyrek|çeyrek|yarim|yarım|tam|cumhuriyet|ata/
17
- urls[:altin]
18
- else
19
- urls[:doviz]
20
- end
21
-
22
- islem = if islem =~ /al|almak|alabilirim|alirim/
23
- 'buying'
24
- else
25
- 'selling'
26
- end
27
-
28
- return hesapla(url, ne, islem)
6
+ def initialize(opts)
7
+ urls = {
8
+ altin: 'http://www.doviz.com/api/v1/golds/all/latest',
9
+ doviz: 'http://www.doviz.com/api/v1/currencies/all/latest'
10
+ }
11
+
12
+ altinlar = %w(ceyrek-altin yarim-altin tam-altin cumhuriyet-altini ata-altin besli-altin gumus)
13
+ birimler = %w(amerikan-dolari euro sterlin isvicre-frangi rus-rublesi japon-yeni)
14
+ ne = FuzzyMatch.new(altinlar + birimler).find(opts[0].downcase)
15
+ url = if altinlar.include? ne
16
+ urls[:altin]
17
+ else
18
+ urls[:doviz]
19
+ end
20
+
21
+ islem = if FuzzyMatch.new(%w(almak alabilirim alırım)).find(opts[1])
22
+ 'selling'
23
+ else
24
+ 'buying'
25
+ end
26
+
27
+ getir(url, ne, islem)
28
+ rescue => e
29
+ puts "Errör: #{e}"
29
30
  end
30
31
 
31
- def hesapla(url, ne, islem)
32
+ def getir(url, ne, islem)
32
33
  uri = URI.parse(url)
33
34
  http = Net::HTTP.new(uri.host)
34
35
  req = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json')
@@ -36,7 +37,7 @@ class Kaca
36
37
  result = JSON.parse(res.body)
37
38
 
38
39
  aranan = result.select { |r| r['name'] == ne }.first
39
- sonuc = "Bugün #{aranan['full_name'].downcase!} #{aranan[islem].to_f.round(2)} TRY e #{islem == 'buying' ? 'alabilirsin' : 'satabilirsin'}."
40
+ sonuc = "Bugün #{aranan['full_name'].downcase!} #{aranan[islem].to_f.round(2)} TRY e #{islem == 'buying' ? 'satabilirsin' : 'alabilirsin'}."
40
41
  puts sonuc
41
42
  rescue => e
42
43
  puts "Errör: #{e}"
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.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murat Bastas
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-05-16 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fuzzy_match
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
13
27
  description: Kaça altın alırım? Kaça dolar satarım? Terminal üzerinden döviz hesabı
14
28
  yapabileceğiniz bir uygulama.
15
29
  email:
@@ -41,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
55
  version: '0'
42
56
  requirements: []
43
57
  rubyforge_project:
44
- rubygems_version: 2.5.2
58
+ rubygems_version: 2.6.12
45
59
  signing_key:
46
60
  specification_version: 4
47
61
  summary: Kaca alır satarım?