currency_numberal 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 571c7f773b8146f36f8b4a47a5b82216848e29f3a7cd95c74fbaadc763c5009a
4
- data.tar.gz: 9aa5582218e7f9d464ea4f675c468a71634f8004f064aa3c2826c1f5ed004334
3
+ metadata.gz: 6af5f340f1d1884f2c35e0f4527d1da0000e221ae3122813fc428b4f16ea7502
4
+ data.tar.gz: c0af24c2cd7c4ce80aacb876904026de925382f075b9a888ecb9df68a7a58b38
5
5
  SHA512:
6
- metadata.gz: 46eeb0842036153290b74771981e2d2ab1674e4b33d3bd25a62e99c0968cf48f19a94611512e68946fc2394232a79392e37a4087a7a22dcf8e20d0e7f39d83a6
7
- data.tar.gz: 605be5dbf9f3d422300923af539bd271d859b55897483bd1785c4a76ee463682754034e1e912fddf9fa252cac95091f342d5f62f9f1d8367433885f896d95b31
6
+ metadata.gz: 9aa62d234b1e4fe01704b294b825067c9254ec27f410fb174816d1837c1e0bd5268371615eaa28b746ba2f9d752046fa5df8146083661d77d29fe94724484e56
7
+ data.tar.gz: ece85b71d47af2aa6393be5732e61615dd99588fb04d4b09b56486bead312483604409da92c18bb85f2e3bcef1c5a8f27c38e11653d95b6d4c0efac3359604b8
data/CHANGELOG.md CHANGED
@@ -3,3 +3,7 @@
3
3
  ## [0.1.0] - 2022-01-07
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.1] - 2022-01-13
8
+
9
+ - Fix separator number bug
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- currency_numberal (0.1.0)
4
+ currency_numberal (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -41,6 +41,11 @@ puts 1.use / 2
41
41
 
42
42
  1.usd == 2.usd
43
43
  # => false
44
+
45
+ # update exchange rate
46
+ CurrencyNumberal.exchange_rate(base: :jpy, code: :vnd, rate: 300)
47
+ puts 1.jpy.vnd
48
+ # => 300.0 ₫
44
49
  ```
45
50
 
46
51
  ## Development
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CurrencyNumberal
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
@@ -6,6 +6,14 @@ require_relative 'currency_numberal/currencies'
6
6
  module CurrencyNumberal
7
7
  class Error < StandardError; end
8
8
 
9
+ def self.exchange_rate(base:, code:, rate:)
10
+ raise Error, 'Invalid base' unless CurrencyNumberal::CURRENCIES.key?(base)
11
+
12
+ raise Error, 'Invalid code' unless CurrencyNumberal::CURRENCIES.key?(code)
13
+
14
+ CurrencyNumberal::CURRENCIES[code][:base] = rate * 1.usd.jpy.to_f
15
+ end
16
+
9
17
  class Currency < Numeric
10
18
  attr_accessor :code, :number
11
19
 
@@ -21,13 +29,17 @@ module CurrencyNumberal
21
29
  end
22
30
 
23
31
  def to_s
24
- "#{@number.to_s.gsub(/\B(?=(...)*\b)/, ',')} #{symbol}"
32
+ "#{@number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse} #{symbol}"
25
33
  end
26
34
 
27
35
  def to_f
28
36
  @number.to_f
29
37
  end
30
38
 
39
+ def to_i
40
+ @number.to_i
41
+ end
42
+
31
43
  def base
32
44
  @number.to_f / CurrencyNumberal::CURRENCIES[@code][:base]
33
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currency_numberal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - vinhactindi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-11 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple currency exchange library.
14
14
  email: