lumione 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7d38112ecdfa2a5e8457c75bd998adca198d7166d064f65688adc45466467c32
4
+ data.tar.gz: 6780921b5af3a50d321aa7df57c40c3f2059c38712a0b28aeaec91314a1c4e02
5
+ SHA512:
6
+ metadata.gz: 646c02d4e703da7ab1c5b2a21413c3dc23d45bb7205c0f4ef579e372f07ac05ff58b5a44b7c734acbe7c7730c334a1bf6dab0bd86cfa6de9cf6f06a4837ef84e
7
+ data.tar.gz: 5bee2c5367fc9c130dc3862efcb45cfb5950fa0fee6424262f573fd37703932e9154ebab325a1bc38694c252b7854e727834ece5ce873392775c40fea7a32e73
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
5
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lumione.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lumione (0.1.0)
5
+ actionview (~> 6.0)
6
+ activesupport (~> 6.0)
7
+ eu_central_bank (~> 1.5)
8
+ optparse-plus (~> 3.0.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ actionview (6.0.3.3)
14
+ activesupport (= 6.0.3.3)
15
+ builder (~> 3.1)
16
+ erubi (~> 1.4)
17
+ rails-dom-testing (~> 2.0)
18
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
19
+ activesupport (6.0.3.3)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (>= 0.7, < 2)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ zeitwerk (~> 2.2, >= 2.2.2)
25
+ builder (3.2.4)
26
+ concurrent-ruby (1.1.7)
27
+ crass (1.0.6)
28
+ diff-lcs (1.4.4)
29
+ erubi (1.9.0)
30
+ eu_central_bank (1.5.0)
31
+ money (~> 6.13, >= 6.13.6)
32
+ nokogiri (~> 1.9)
33
+ i18n (1.8.5)
34
+ concurrent-ruby (~> 1.0)
35
+ loofah (2.7.0)
36
+ crass (~> 1.0.2)
37
+ nokogiri (>= 1.5.9)
38
+ mini_portile2 (2.4.0)
39
+ minitest (5.14.2)
40
+ money (6.13.8)
41
+ i18n (>= 0.6.4, <= 2)
42
+ nokogiri (1.10.10)
43
+ mini_portile2 (~> 2.4.0)
44
+ optparse-plus (3.0.0)
45
+ bundler
46
+ rails-dom-testing (2.0.3)
47
+ activesupport (>= 4.2.0)
48
+ nokogiri (>= 1.6)
49
+ rails-html-sanitizer (1.3.0)
50
+ loofah (~> 2.3)
51
+ rake (12.3.3)
52
+ rdoc (6.2.1)
53
+ rspec (3.9.0)
54
+ rspec-core (~> 3.9.0)
55
+ rspec-expectations (~> 3.9.0)
56
+ rspec-mocks (~> 3.9.0)
57
+ rspec-core (3.9.2)
58
+ rspec-support (~> 3.9.3)
59
+ rspec-expectations (3.9.2)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.9.0)
62
+ rspec-mocks (3.9.1)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.9.0)
65
+ rspec-support (3.9.3)
66
+ thread_safe (0.3.6)
67
+ tzinfo (1.2.7)
68
+ thread_safe (~> 0.1)
69
+ zeitwerk (2.4.0)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ lumione!
76
+ rake (~> 12.0)
77
+ rdoc (~> 6.2)
78
+ rspec (~> 3)
79
+
80
+ BUNDLED WITH
81
+ 2.1.4
@@ -0,0 +1,8 @@
1
+ Name: lumione
2
+ Copyright (c) 2020 Dmitry Maksyoma
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # lumione
2
+
3
+ Convert money in one currency into another
4
+
5
+ # Usage
6
+
7
+ ```
8
+ $lumione 26 nzd usd
9
+ $26.00 NZD ($17.04 USD)
10
+ ```
11
+
12
+ The rates used are from the EU bank and are updated not real-time, but once in
13
+ 1-2 days, it seems.
14
+
15
+ # Install
16
+
17
+ ```
18
+ gem install lumione
19
+ ```
20
+
21
+ # License
22
+
23
+ MIT, see LICENSE.txt
@@ -0,0 +1,57 @@
1
+ def dump_load_path
2
+ puts $LOAD_PATH.join("\n")
3
+ found = nil
4
+ $LOAD_PATH.each do |path|
5
+ if File.exists?(File.join(path,"rspec"))
6
+ puts "Found rspec in #{path}"
7
+ if File.exists?(File.join(path,"rspec","core"))
8
+ puts "Found core"
9
+ if File.exists?(File.join(path,"rspec","core","rake_task"))
10
+ puts "Found rake_task"
11
+ found = path
12
+ else
13
+ puts "!! no rake_task"
14
+ end
15
+ else
16
+ puts "!!! no core"
17
+ end
18
+ end
19
+ end
20
+ if found.nil?
21
+ puts "Didn't find rspec/core/rake_task anywhere"
22
+ else
23
+ puts "Found in #{path}"
24
+ end
25
+ end
26
+ require 'bundler'
27
+ require 'rake/clean'
28
+
29
+ begin
30
+ require 'rspec/core/rake_task'
31
+ rescue LoadError
32
+ dump_load_path
33
+ raise
34
+ end
35
+
36
+ gem 'rdoc' # we need the installed RDoc gem, not the system one
37
+ require 'rdoc/task'
38
+
39
+ include Rake::DSL
40
+
41
+ Bundler::GemHelper.install_tasks
42
+
43
+
44
+ RSpec::Core::RakeTask.new do |t|
45
+ # Put spec opts in a file named .rspec in root
46
+ end
47
+
48
+
49
+ Rake::RDocTask.new do |rd|
50
+
51
+ rd.main = "README.rdoc"
52
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
53
+
54
+ end
55
+
56
+ task :default => [:spec]
57
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lumione"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'optparse_plus'
5
+ require 'lumione.rb'
6
+
7
+ class App
8
+ include OptparsePlus::Main
9
+ include OptparsePlus::CLILogging
10
+
11
+ main do |amount, original_currency, converted_to_currency|
12
+ amount = convert_amount_to_number amount
13
+
14
+ Lumione.convert_and_print amount, original_currency, converted_to_currency
15
+ end
16
+
17
+ def self.convert_amount_to_number(amount)
18
+ begin
19
+ Float(amount)
20
+ rescue ArgumentError
21
+ raise "#{amount}: Invalid amount, please use a number"
22
+ end
23
+ end
24
+
25
+ # supplemental methods here
26
+
27
+ arg :amount
28
+ arg :original_currency
29
+ arg :converted_to_currency
30
+
31
+ # Declare command-line interface here
32
+
33
+ #
34
+ # Accept flags via:
35
+ # on("--flag VAL","Some flag")
36
+ # options[flag] will contain VAL
37
+ #
38
+ # Specify switches via:
39
+ # on("--[no-]switch","Some switch")
40
+ #
41
+ # Or, just call OptionParser methods on opts
42
+ #
43
+ # Require an argument
44
+ # arg :some_arg
45
+ #
46
+ # # Make an argument optional
47
+ # arg :optional_arg, :optional
48
+
49
+ version Lumione::VERSION
50
+
51
+ use_log_level_option :toggle_debug_on_signal => 'USR1'
52
+
53
+ description "Convert money in one currency into another"
54
+
55
+ go!
56
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ require "lumione/version"
2
+ require "lumione/initializer"
3
+ require "lumione/bank"
4
+
5
+ module Lumione
6
+ class Error < StandardError; end
7
+
8
+ def self.convert_and_print(amount, from_currency, to_currency)
9
+ Bank.convert_and_print amount, from_currency, to_currency
10
+ end
11
+ end
@@ -0,0 +1,88 @@
1
+ require "fileutils"
2
+ require "active_support/core_ext/numeric/time"
3
+ require 'action_view'
4
+
5
+ module Lumione
6
+ class Bank
7
+ include ActionView::Helpers::DateHelper
8
+
9
+ DEFAULT_CACHE_DIR = File.join(Dir.home, ".cache", "lumione")
10
+ CACHE_DIR = ENV["LUMIONE_CACHE_DIR"] || DEFAULT_CACHE_DIR
11
+ CACHE_FILE = File.join(CACHE_DIR, "exchange_rates.xml")
12
+
13
+ def self.convert_and_print(amount, from_currency, to_currency)
14
+ new.convert_and_print amount, from_currency, to_currency
15
+ end
16
+
17
+ def convert_and_print(amount, from_currency, to_currency)
18
+ prepare_rates
19
+
20
+ convert(amount, from_currency, to_currency)
21
+
22
+ print_original_and_converted_money
23
+ end
24
+
25
+ def print_original_and_converted_money
26
+ print format_conversion(@original_money, @converted_money)
27
+ if bank.rates_updated_at < 2.days.ago
28
+ print " (#{how_long_since_rates_were_updated(bank.rates_updated_at)})"
29
+ end
30
+ puts
31
+ end
32
+
33
+ def convert(amount, from_currency, to_currency)
34
+ @original_money = Money.from_amount(amount, from_currency)
35
+ @converted_money = @original_money.exchange_to(to_currency)
36
+ end
37
+
38
+ def prepare_rates
39
+ create_cache_dir
40
+ update_and_load_rates
41
+ end
42
+
43
+ private
44
+
45
+ def bank
46
+ Money.default_bank
47
+ end
48
+
49
+ def create_cache_dir
50
+ cache_dir = File.dirname CACHE_FILE
51
+ FileUtils.mkdir_p cache_dir
52
+ end
53
+
54
+ def update_and_load_rates
55
+ load_rates_from_cache
56
+ return if up_to_date_rates?
57
+
58
+ fetch_rates_and_save_to_cache
59
+ load_rates_from_cache
60
+ end
61
+
62
+ def fetch_rates_and_save_to_cache
63
+ bank.save_rates(CACHE_FILE)
64
+ end
65
+
66
+ def up_to_date_rates?
67
+ !stale_rates?
68
+ end
69
+
70
+ def stale_rates?
71
+ !bank.rates_updated_at || File.mtime(CACHE_FILE) < 1.day.ago
72
+ end
73
+
74
+ def load_rates_from_cache
75
+ bank.update_rates(CACHE_FILE) if File.exists? CACHE_FILE
76
+ end
77
+
78
+ def how_long_since_rates_were_updated(rates_updated_at)
79
+ "rates updated #{distance_of_time_in_words_to_now rates_updated_at} ago"
80
+ end
81
+
82
+ def format_conversion(original_money, converted_money)
83
+ formatted_original_money = original_money.format(with_currency: true)
84
+ formatted_converted_money = converted_money.format(with_currency: true)
85
+ "#{formatted_original_money} (#{formatted_converted_money})"
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,13 @@
1
+ require "eu_central_bank"
2
+
3
+ module Initializer
4
+ def self.configure_money_gem
5
+ I18n.config.available_locales = :en
6
+ I18n.locale = :en
7
+ Money.locale_backend = :i18n
8
+ Money.rounding_mode= BigDecimal::ROUND_HALF_UP
9
+ Money.default_bank = EuCentralBank.new
10
+ end
11
+ end
12
+
13
+ Initializer.configure_money_gem
@@ -0,0 +1,3 @@
1
+ module Lumione
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'lib/lumione/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "lumione"
5
+ spec.license = "MIT"
6
+ spec.version = Lumione::VERSION
7
+ spec.authors = ["Dmitry Maksyoma"]
8
+ spec.email = ["ledestin@gmail.com"]
9
+
10
+ spec.summary = %q{Convert money in one currency into another}
11
+ spec.homepage = "https://github.com/ledestin/lumione"
12
+
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ #spec.metadata["changelog_uri"] = "to-do: Put your gem's CHANGELOG.md URL here."
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "bin"
25
+ spec.executables = "lumione"
26
+ spec.require_paths = ["lib"]
27
+ spec.add_development_dependency('rdoc', '~> 6.2')
28
+ spec.add_dependency('optparse-plus', '~> 3.0.0')
29
+ spec.add_dependency('activesupport', '~> 6.0')
30
+ spec.add_dependency('actionview', '~> 6.0')
31
+ spec.add_dependency('eu_central_bank', '~> 1.5')
32
+ spec.add_development_dependency('rspec', '~> 3')
33
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lumione
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Maksyoma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rdoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: optparse-plus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: actionview
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: eu_central_bank
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3'
97
+ description:
98
+ email:
99
+ - ledestin@gmail.com
100
+ executables:
101
+ - lumione
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/lumione
113
+ - bin/setup
114
+ - lib/lumione.rb
115
+ - lib/lumione/bank.rb
116
+ - lib/lumione/initializer.rb
117
+ - lib/lumione/version.rb
118
+ - lumione.gemspec
119
+ homepage: https://github.com/ledestin/lumione
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ source_code_uri: https://github.com/ledestin/lumione
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.3.0
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubygems_version: 3.1.4
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Convert money in one currency into another
143
+ test_files: []