crypto_converter 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b505231d7d319279d04e3d8b884bfc9d8d5fdfa7
4
+ data.tar.gz: 8c63020bf84b58d30b81bdadd299236a9901e1a3
5
+ SHA512:
6
+ metadata.gz: eff2d01cd014c192457aa71e4751307510a948786bf80e7aa9979175bf448a6bde9d6c5060b696daa83cc5ddd257c667297afb853661dfc7f3e60f0b4f157193
7
+ data.tar.gz: 24934d70595c674239c153f61d3f5af01be138cbafecdba2a466c387a7f64e5ca1ce942a77110a8b5e69efa72e0a4ac26314c0c5dc19ed9c2248aa453ea96dd8
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ class Converter
5
+ attr_reader :currencies_json, :current_currency, :targeted_currency
6
+
7
+ def initialize(current_currency, targeted_currency, currencies_path)
8
+ @current_currency = current_currency
9
+ @targeted_currency = targeted_currency
10
+ @currencies_path = currencies_path
11
+ refresh
12
+ end
13
+
14
+ def refresh
15
+ uri = URI.parse(@currencies_path)
16
+ response = Net::HTTP.get(uri)
17
+ @currencies_json = JSON.parse(response)
18
+ end
19
+
20
+ def convert(amount, from = nil, to = nil)
21
+ from ||= @current_currency
22
+ to ||= @targeted_currency
23
+ (amount.to_f * @currencies_json[from].to_f) / @currencies_json[to].to_f
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ require 'crypto_converter/converter'
2
+
3
+ class CryptoConverter
4
+ def self.init(current_currency, targeted_currency, currencies_path = "http://localhost:3000/api/v1/currencies")
5
+ @converter = Converter.new(current_currency, targeted_currency, currencies_path)
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crypto_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Saascoin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A cryptocurrency converter from any currency to any
14
+ email: ibrahim@getsaascoin.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - Rakefile
20
+ - lib/crypto_converter.rb
21
+ - lib/crypto_converter/converter.rb
22
+ homepage: http://rubygems.org/gems/crypto_converter
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Cryptocurrency converter
46
+ test_files: []