tiny-sharp-rb 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.
@@ -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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Money
4
+ VERSION = "7.0.2"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bigdecimal"
4
+ require "bigdecimal/util"
5
+ require "set"
6
+ require "i18n"
7
+ require "money/currency"
8
+ require "money/money"
9
+ require "money/version"
@@ -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
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "tiny-sharp-rb"
3
+ s.version = "0.0.1"
4
+ s.summary = "Research test"
5
+ s.description = "University research based on money"
6
+ s.authors = ["Andrey78"]
7
+ s.email = ["cakoc614@gmail.com"]
8
+ s.files = Dir.glob("**/*").reject { |f| f.end_with?('.gem') }
9
+ s.homepage = "https://rubygems.org/profiles/Andrey78"
10
+ s.license = "MIT"
11
+ s.metadata = { "source_code_uri" => "https://github.com/Andrey78/tiny-sharp-rb" }
12
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny-sharp-rb
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-05 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
+ - money-7.0.2/CHANGELOG.md
20
+ - money-7.0.2/LICENSE
21
+ - money-7.0.2/README.md
22
+ - money-7.0.2/config/currency_backwards_compatible.json
23
+ - money-7.0.2/config/currency_iso.json
24
+ - money-7.0.2/config/currency_non_iso.json
25
+ - money-7.0.2/lib/money.rb
26
+ - money-7.0.2/lib/money/bank/base.rb
27
+ - money-7.0.2/lib/money/bank/single_currency.rb
28
+ - money-7.0.2/lib/money/bank/variable_exchange.rb
29
+ - money-7.0.2/lib/money/currency.rb
30
+ - money-7.0.2/lib/money/currency/heuristics.rb
31
+ - money-7.0.2/lib/money/currency/loader.rb
32
+ - money-7.0.2/lib/money/locale_backend/base.rb
33
+ - money-7.0.2/lib/money/locale_backend/currency.rb
34
+ - money-7.0.2/lib/money/locale_backend/errors.rb
35
+ - money-7.0.2/lib/money/locale_backend/i18n.rb
36
+ - money-7.0.2/lib/money/money.rb
37
+ - money-7.0.2/lib/money/money/allocation.rb
38
+ - money-7.0.2/lib/money/money/arithmetic.rb
39
+ - money-7.0.2/lib/money/money/constructors.rb
40
+ - money-7.0.2/lib/money/money/formatter.rb
41
+ - money-7.0.2/lib/money/money/formatting_rules.rb
42
+ - money-7.0.2/lib/money/money/locale_backend.rb
43
+ - money-7.0.2/lib/money/rates_store/memory.rb
44
+ - money-7.0.2/lib/money/version.rb
45
+ - money-7.0.2/money.gemspec
46
+ - tiny-sharp-rb.gemspec
47
+ homepage: https://rubygems.org/profiles/Andrey78
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ source_code_uri: https://github.com/Andrey78/tiny-sharp-rb
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.6.2
67
+ specification_version: 4
68
+ summary: Research test
69
+ test_files: []