rate_man 0.0.7 → 0.0.8

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.
Files changed (3) hide show
  1. data/lib/rate_man/version.rb +1 -1
  2. data/lib/rate_man.rb +9 -13
  3. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module RateMan
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/rate_man.rb CHANGED
@@ -10,6 +10,14 @@ module RateMan
10
10
 
11
11
  mattr_accessor :api_key, :google_api_url, :custom_search_id
12
12
 
13
+ def self.proper_line(snippet)
14
+ snippet.split('...').select { |l| RateMan.match(l.gsub(/^\s/,'').gsub(/\s$/,'')) }.first
15
+ end
16
+
17
+ def self.match(string)
18
+ string =~ /\d EUR = \d*\.\d* CHF [-\+]?\d*\.\d* \([-\+]?\d*\.\d*\%\)/
19
+ end
20
+
13
21
  def self.query_url(from_cur, to_cur)
14
22
  "#{@@google_api_url}?key=#{self.api_key}&cx=#{@@custom_search_id}&q=1%20#{from_cur}%20to%20#{to_cur}"
15
23
  end
@@ -30,19 +38,7 @@ module RateMan
30
38
  end
31
39
 
32
40
  def self.query(from_cur, to_cur)
33
- incorrect = true
34
- acceptable_time = true
35
- i = 0
36
- while incorrect && acceptable_time
37
- string = JSON.parse(RateMan.raw_response(from_cur, to_cur))['items'].first['snippet'].split('...')[1]
38
- incorrect = false if string =~ /\d EUR = \d*\.\d* CHF [-\+]?\d*\.\d* \([-\+]?\d*\.\d*\%\)/
39
- i += 1
40
- acceptable_time = false if i > 5
41
- end
42
- if incorrect
43
- raise ArgumentError, "incorrect json"
44
- end
45
- string.split(' ')
41
+ RateMan.proper_line(JSON.parse(RateMan.raw_response(from_cur, to_cur))['items'].first['snippet']).split(' ')
46
42
  end
47
43
 
48
44
  def self.get(from_cur, to_cur)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rate_man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: -3656385961126346063
56
+ hash: 2585839282254537821
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements: