micro-lite-lib 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 +7 -0
- data/micro-lite-lib.gemspec +11 -0
- data/money-7.0.2/CHANGELOG.md +843 -0
- data/money-7.0.2/LICENSE +23 -0
- data/money-7.0.2/README.md +626 -0
- data/money-7.0.2/config/currency_backwards_compatible.json +225 -0
- data/money-7.0.2/config/currency_iso.json +2750 -0
- data/money-7.0.2/config/currency_non_iso.json +146 -0
- data/money-7.0.2/lib/money/bank/base.rb +130 -0
- data/money-7.0.2/lib/money/bank/single_currency.rb +26 -0
- data/money-7.0.2/lib/money/bank/variable_exchange.rb +285 -0
- data/money-7.0.2/lib/money/currency/heuristics.rb +11 -0
- data/money-7.0.2/lib/money/currency/loader.rb +28 -0
- data/money-7.0.2/lib/money/currency.rb +477 -0
- data/money-7.0.2/lib/money/locale_backend/base.rb +9 -0
- data/money-7.0.2/lib/money/locale_backend/currency.rb +13 -0
- data/money-7.0.2/lib/money/locale_backend/errors.rb +8 -0
- data/money-7.0.2/lib/money/locale_backend/i18n.rb +28 -0
- data/money-7.0.2/lib/money/money/allocation.rb +87 -0
- data/money-7.0.2/lib/money/money/arithmetic.rb +346 -0
- data/money-7.0.2/lib/money/money/constructors.rb +86 -0
- data/money-7.0.2/lib/money/money/formatter.rb +361 -0
- data/money-7.0.2/lib/money/money/formatting_rules.rb +92 -0
- data/money-7.0.2/lib/money/money/locale_backend.rb +20 -0
- data/money-7.0.2/lib/money/money.rb +664 -0
- data/money-7.0.2/lib/money/rates_store/memory.rb +122 -0
- data/money-7.0.2/lib/money/version.rb +5 -0
- data/money-7.0.2/lib/money.rb +9 -0
- data/money-7.0.2/money.gemspec +32 -0
- metadata +68 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'monitor'
|
|
4
|
+
|
|
5
|
+
class Money
|
|
6
|
+
module RatesStore
|
|
7
|
+
|
|
8
|
+
# Class for thread-safe storage of exchange rate pairs.
|
|
9
|
+
# Used by instances of +Money::Bank::VariableExchange+.
|
|
10
|
+
#
|
|
11
|
+
# @example
|
|
12
|
+
# store = Money::RatesStore::Memory.new
|
|
13
|
+
# store.add_rate 'USD', 'CAD', 0.98
|
|
14
|
+
# store.get_rate 'USD', 'CAD' # => 0.98
|
|
15
|
+
# # iterates rates
|
|
16
|
+
# store.each_rate {|iso_from, iso_to, rate| puts "#{from} -> #{to}: #{rate}" }
|
|
17
|
+
class Memory
|
|
18
|
+
INDEX_KEY_SEPARATOR = '_TO_'.freeze
|
|
19
|
+
|
|
20
|
+
# Initializes a new +Money::RatesStore::Memory+ object.
|
|
21
|
+
#
|
|
22
|
+
# @param [Hash] opts Optional store options.
|
|
23
|
+
# @option opts [Boolean] :without_mutex disables the usage of a mutex
|
|
24
|
+
# @param [Hash] rates Optional initial exchange rate data.
|
|
25
|
+
def initialize(opts = {}, rates = {})
|
|
26
|
+
@rates = rates
|
|
27
|
+
@options = opts
|
|
28
|
+
@guard = Monitor.new
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Registers a conversion rate and returns it. Uses +Mutex+ to synchronize data access.
|
|
32
|
+
#
|
|
33
|
+
# @param [String] currency_iso_from Currency to exchange from.
|
|
34
|
+
# @param [String] currency_iso_to Currency to exchange to.
|
|
35
|
+
# @param [Numeric] rate Rate to use when exchanging currencies.
|
|
36
|
+
#
|
|
37
|
+
# @return [Numeric]
|
|
38
|
+
#
|
|
39
|
+
# @example
|
|
40
|
+
# store = Money::RatesStore::Memory.new
|
|
41
|
+
# store.add_rate("USD", "CAD", 1.24515)
|
|
42
|
+
# store.add_rate("CAD", "USD", 0.803115)
|
|
43
|
+
def add_rate(currency_iso_from, currency_iso_to, rate)
|
|
44
|
+
guard.synchronize do
|
|
45
|
+
rates[rate_key_for(currency_iso_from, currency_iso_to)] = rate
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Retrieve the rate for the given currencies. Uses +Mutex+ to synchronize data access.
|
|
50
|
+
# Delegates to +Money::RatesStore::Memory+
|
|
51
|
+
#
|
|
52
|
+
# @param [String] currency_iso_from Currency to exchange from.
|
|
53
|
+
# @param [String] currency_iso_to Currency to exchange to.
|
|
54
|
+
#
|
|
55
|
+
# @return [Numeric]
|
|
56
|
+
#
|
|
57
|
+
# @example
|
|
58
|
+
# store = Money::RatesStore::Memory.new
|
|
59
|
+
# store.add_rate("USD", "CAD", 1.24515)
|
|
60
|
+
#
|
|
61
|
+
# store.get_rate("USD", "CAD") #=> 1.24515
|
|
62
|
+
def get_rate(currency_iso_from, currency_iso_to)
|
|
63
|
+
guard.synchronize do
|
|
64
|
+
rates[rate_key_for(currency_iso_from, currency_iso_to)]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def marshal_dump
|
|
69
|
+
guard.synchronize do
|
|
70
|
+
return [self.class, options, rates.dup]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Wraps block execution in a thread-safe transaction
|
|
75
|
+
def transaction(&block)
|
|
76
|
+
guard.synchronize do
|
|
77
|
+
yield
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Iterate over rate tuples (iso_from, iso_to, rate)
|
|
82
|
+
#
|
|
83
|
+
# @yieldparam iso_from [String] Currency ISO string.
|
|
84
|
+
# @yieldparam iso_to [String] Currency ISO string.
|
|
85
|
+
# @yieldparam rate [Numeric] Exchange rate.
|
|
86
|
+
#
|
|
87
|
+
# @return [Enumerator]
|
|
88
|
+
#
|
|
89
|
+
# @example
|
|
90
|
+
# store.each_rate do |iso_from, iso_to, rate|
|
|
91
|
+
# puts [iso_from, iso_to, rate].join
|
|
92
|
+
# end
|
|
93
|
+
def each_rate(&block)
|
|
94
|
+
return to_enum(:each_rate) unless block_given?
|
|
95
|
+
|
|
96
|
+
guard.synchronize do
|
|
97
|
+
rates.each do |key, rate|
|
|
98
|
+
iso_from, iso_to = key.split(INDEX_KEY_SEPARATOR)
|
|
99
|
+
yield iso_from, iso_to, rate
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
private
|
|
105
|
+
|
|
106
|
+
attr_reader :rates, :options, :guard
|
|
107
|
+
|
|
108
|
+
# Return the rate hashkey for the given currencies.
|
|
109
|
+
#
|
|
110
|
+
# @param [String] currency_iso_from The currency to exchange from.
|
|
111
|
+
# @param [String] currency_iso_to The currency to exchange to.
|
|
112
|
+
#
|
|
113
|
+
# @return [String]
|
|
114
|
+
#
|
|
115
|
+
# @example
|
|
116
|
+
# rate_key_for("USD", "CAD") #=> "USD_TO_CAD"
|
|
117
|
+
def rate_key_for(currency_iso_from, currency_iso_to)
|
|
118
|
+
[currency_iso_from, currency_iso_to].join(INDEX_KEY_SEPARATOR).upcase
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "money/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |s|
|
|
8
|
+
s.name = "money"
|
|
9
|
+
s.version = Money::VERSION
|
|
10
|
+
s.platform = Gem::Platform::RUBY
|
|
11
|
+
s.authors = ['Shane Emmons', 'Anthony Dmitriyev']
|
|
12
|
+
s.email = ['shane@emmons.io', 'anthony.dmitriyev@gmail.com']
|
|
13
|
+
s.homepage = "https://rubymoney.github.io/money"
|
|
14
|
+
s.summary = "A Ruby Library for dealing with money and currency conversion."
|
|
15
|
+
s.description = "A Ruby Library for dealing with money and currency conversion."
|
|
16
|
+
s.license = "MIT"
|
|
17
|
+
|
|
18
|
+
s.add_dependency "bigdecimal"
|
|
19
|
+
s.add_dependency "i18n", "~> 1.9"
|
|
20
|
+
|
|
21
|
+
s.required_ruby_version = ">= 3.1"
|
|
22
|
+
|
|
23
|
+
s.files = `git ls-files -z -- config/* lib/* CHANGELOG.md LICENSE money.gemspec README.md`.split("\x0")
|
|
24
|
+
s.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
if s.respond_to?(:metadata)
|
|
27
|
+
s.metadata['changelog_uri'] = 'https://github.com/RubyMoney/money/blob/main/CHANGELOG.md'
|
|
28
|
+
s.metadata['source_code_uri'] = 'https://github.com/RubyMoney/money/'
|
|
29
|
+
s.metadata['bug_tracker_uri'] = 'https://github.com/RubyMoney/money/issues'
|
|
30
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
31
|
+
end
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: micro-lite-lib
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrey78
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-07-06 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: University research based on money
|
|
13
|
+
email:
|
|
14
|
+
- cakoc614@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- micro-lite-lib.gemspec
|
|
20
|
+
- money-7.0.2/CHANGELOG.md
|
|
21
|
+
- money-7.0.2/LICENSE
|
|
22
|
+
- money-7.0.2/README.md
|
|
23
|
+
- money-7.0.2/config/currency_backwards_compatible.json
|
|
24
|
+
- money-7.0.2/config/currency_iso.json
|
|
25
|
+
- money-7.0.2/config/currency_non_iso.json
|
|
26
|
+
- money-7.0.2/lib/money.rb
|
|
27
|
+
- money-7.0.2/lib/money/bank/base.rb
|
|
28
|
+
- money-7.0.2/lib/money/bank/single_currency.rb
|
|
29
|
+
- money-7.0.2/lib/money/bank/variable_exchange.rb
|
|
30
|
+
- money-7.0.2/lib/money/currency.rb
|
|
31
|
+
- money-7.0.2/lib/money/currency/heuristics.rb
|
|
32
|
+
- money-7.0.2/lib/money/currency/loader.rb
|
|
33
|
+
- money-7.0.2/lib/money/locale_backend/base.rb
|
|
34
|
+
- money-7.0.2/lib/money/locale_backend/currency.rb
|
|
35
|
+
- money-7.0.2/lib/money/locale_backend/errors.rb
|
|
36
|
+
- money-7.0.2/lib/money/locale_backend/i18n.rb
|
|
37
|
+
- money-7.0.2/lib/money/money.rb
|
|
38
|
+
- money-7.0.2/lib/money/money/allocation.rb
|
|
39
|
+
- money-7.0.2/lib/money/money/arithmetic.rb
|
|
40
|
+
- money-7.0.2/lib/money/money/constructors.rb
|
|
41
|
+
- money-7.0.2/lib/money/money/formatter.rb
|
|
42
|
+
- money-7.0.2/lib/money/money/formatting_rules.rb
|
|
43
|
+
- money-7.0.2/lib/money/money/locale_backend.rb
|
|
44
|
+
- money-7.0.2/lib/money/rates_store/memory.rb
|
|
45
|
+
- money-7.0.2/lib/money/version.rb
|
|
46
|
+
- money-7.0.2/money.gemspec
|
|
47
|
+
homepage: https://rubygems.org/profiles/Andrey78
|
|
48
|
+
licenses:
|
|
49
|
+
- MIT
|
|
50
|
+
metadata: {}
|
|
51
|
+
rdoc_options: []
|
|
52
|
+
require_paths:
|
|
53
|
+
- lib
|
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
requirements: []
|
|
65
|
+
rubygems_version: 3.6.2
|
|
66
|
+
specification_version: 4
|
|
67
|
+
summary: Research test
|
|
68
|
+
test_files: []
|