currency_finance_ua 0.1.1

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.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ idea
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in currency_finance_ua.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ currency_finance_ua (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.1.0)
10
+
11
+ PLATFORMS
12
+ x86-mingw32
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.5)
16
+ currency_finance_ua!
17
+ rake
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ruslanpa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # CurrencyFinanceUa
2
+
3
+ It's a simple wrapper under <http://content.finance.ua/ru/xml/currency-cash>
4
+
5
+ All data provided by <http://content.finance.ua/ru/xml/currency-cash>
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'currency_finance_ua'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install currency_finance_ua
20
+
21
+ ## Usage
22
+
23
+ $ require 'currency_finance_ua'
24
+
25
+ Get rate of exchange by current date
26
+ rate: 'min' or 'max'
27
+ bid_ask: 'bid' or 'ask' spread
28
+ return organizations which are satisfied for all options
29
+
30
+ $ include CurrencyFinanceUA
31
+ $ get_rate_of_exchange('EUR', { rate: 'min', bid_ask: 'ask' })
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( http://github.com/ruslanpa/currency_finance_ua/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'currency_finance_ua/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "currency_finance_ua"
8
+ spec.version = CurrencyFinanceUA::VERSION
9
+ spec.authors = ["ruslanpa"]
10
+ spec.email = ["ruslan.pavlutskiy@gmail.com"]
11
+ spec.description = %q{It's a simple wrapper under <http://content.finance.ua/ru/xml/currency-cash>}
12
+ spec.summary = %q{It's a simple wrapper under <http://content.finance.ua/ru/xml/currency-cash>}
13
+ spec.homepage = "https://github.com/ruslanpa/currency_finance_ua"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,64 @@
1
+ require "currency_finance_ua/version"
2
+ require "currency_finance_ua/entity/exchanger"
3
+ require "open-uri"
4
+ require "json"
5
+
6
+ # It's a simple wrapper under <http://content.finance.ua/ru/xml/currency-cash>
7
+ #
8
+ # Return organizations which are satisfied for all options.
9
+ module CurrencyFinanceUA
10
+ attr_reader :currency, :option, :exchangers, :cities, :rates
11
+
12
+ # Example:
13
+ # $ get_rate_of_exchange('EUR', { rate: 'min', bid_ask: 'ask' })
14
+ #
15
+ # Arguments:
16
+ # currency: (String)
17
+ # option: (Hash)
18
+ def get_rate_of_exchange(currency = 'USD', option)
19
+ @currency, @option = currency, option
20
+
21
+ json = JSON.parse(open('http://resources.finance.ua/ua/public/currency-cash.json').read)
22
+
23
+ get_cities json
24
+
25
+ get_exchangers json
26
+
27
+ @exchangers.select { |exchanger| exchanger.rate == @rates.send(@option[:rate]) }
28
+ end
29
+
30
+ # @return available exchangers which are contains currency
31
+ #
32
+ # Arguments:
33
+ # json: (JSON String)
34
+ def get_exchangers(json)
35
+ @exchangers = []
36
+ @rates = []
37
+ json['organizations'].each do |item|
38
+ currency = item['currencies'][@currency.upcase]
39
+ unless currency.nil?
40
+ rate = Float(currency[@option[:bid_ask]])
41
+ @rates << rate
42
+ exchanger = Exchanger.new(
43
+ item['title'],
44
+ "#{find_city_by_id(item['cityId'])}, #{item['address']}",
45
+ item['phone'],
46
+ rate
47
+ )
48
+ @exchangers << exchanger
49
+ end
50
+ end
51
+ end
52
+
53
+ # @return cities as hash object
54
+ def get_cities(json)
55
+ @cities = json['cities'].to_hash
56
+ end
57
+
58
+ # @return city title by id
59
+ def find_city_by_id(city_id)
60
+ @cities[city_id]
61
+ end
62
+
63
+ private :get_exchangers, :get_cities, :find_city_by_id
64
+ end
@@ -0,0 +1,19 @@
1
+ # Exchanger entity class.
2
+ # A place where foreign currency can be exchanged.
3
+ #
4
+ # Arguments:
5
+ # title: (String)
6
+ # address: (String)
7
+ # phone: (String)
8
+ # rate: (Float)
9
+ class Exchanger
10
+ attr_accessor :title, :address, :phone, :rate
11
+
12
+ def initialize(title, address, phone, rate)
13
+ @title, @address, @phone, @rate = title, address, phone, rate
14
+ end
15
+
16
+ def to_s
17
+ "#{@title} | #{phone} | #{@address} | #{@rate} UAH"
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module CurrencyFinanceUA
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'currency_finance_ua'
3
+
4
+ class CurrencyFinanceUATest
5
+
6
+ def test_load
7
+ end
8
+
9
+ def test_min_or_max
10
+ end
11
+
12
+ def test_rate_of_exchange
13
+ end
14
+
15
+ def test_find_city_by_id
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: currency_finance_ua
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ruslanpa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.5'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: It's a simple wrapper under <http://content.finance.ua/ru/xml/currency-cash>
47
+ email:
48
+ - ruslan.pavlutskiy@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - currency_finance_ua.gemspec
60
+ - lib/currency_finance_ua.rb
61
+ - lib/currency_finance_ua/entity/exchanger.rb
62
+ - lib/currency_finance_ua/version.rb
63
+ - test/test_currency_finance_ua.rb
64
+ homepage: https://github.com/ruslanpa/currency_finance_ua
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: It's a simple wrapper under <http://content.finance.ua/ru/xml/currency-cash>
89
+ test_files:
90
+ - test/test_currency_finance_ua.rb