interests 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
  SHA1:
3
- metadata.gz: a9be6b2c88262c28c80dcc15a26d0d5cd851db5e
4
- data.tar.gz: 4164f4c6678d69dec248c44f0a0e6bd97448a4a7
3
+ metadata.gz: f68e0d0ff75ce39417b1d340243d991deaabe1bd
4
+ data.tar.gz: 6a1a2986ff1dd94b9964db3cbdda96ae9e149ffe
5
5
  SHA512:
6
- metadata.gz: d215cb2d3b8f87afff1a384d218cca84f26a5fa719b7fb8de306436b801e807250d212cf086b96abb8af221e567937bc4fd355e2704fc148c8c086f0e19ff41b
7
- data.tar.gz: a0d653ffb6f2d77d82b6e54b80231d2f101a2e283852d5c08832ffcc9c56056e8fc1e217122af1a5621ff973b9dddf5237e08ab007c602f3b4fa4dafd0b1389e
6
+ metadata.gz: ae2fe645dd49127775adbdc0250fc558af87828960cb037f3ead28cdc1282355aad3e3ea5858c7624e0b6ca7be7ab17c5322c958dedbf945bfa482514f236ed2
7
+ data.tar.gz: f665bac846df25cb325f352108cfaf2c1485aa5b354d4c48bb4ba0793cade5c24effd9ed6016c1d6b1c228c9258095188c9524651b54e5562d5c012be29be185
data/README.md CHANGED
@@ -16,7 +16,7 @@ gem 'interests'
16
16
 
17
17
  Run the bundle command to install it.
18
18
 
19
- Run generator if needed with:
19
+ Run generator if needed:
20
20
 
21
21
  ```console
22
22
  rails generate interests:config
@@ -17,13 +17,7 @@ module Interests
17
17
  prev_rate = nil
18
18
  config_rates.sort!{ |x, y| x.date <=> y.date }
19
19
  ([blank_rate] + config_rates + [blank_rate(till + 1.day, config_rates.last.rate)]).each_with_index do |rate, i|
20
- if i > 0
21
- from_date = prev_rate.date
22
- to_date = rate.date - 1.day
23
- days = (to_date - from_date).to_i
24
- day_rate = prev_rate.rate.to_f / 365
25
- @rates << OpenStruct.new(from_date: from_date, to_date: to_date, days: days, rate: prev_rate.rate, day_rate: day_rate)
26
- end
20
+ add_to_rates(prev_rate, rate, ) if i > 0
27
21
  prev_rate = rate
28
22
  end
29
23
 
@@ -32,15 +26,7 @@ module Interests
32
26
 
33
27
  def interests(amount = 0.0, from_date = BEGINNING_OF_COMPUTER_ERA, to_date = Date.today)
34
28
  rates(to_date).select{ |rate| rate.to_date >= from_date && rate.from_date <= to_date }.map do |rate|
35
- date_beg = [from_date + 1.day, rate.from_date].max
36
- date_end = [to_date, rate.to_date].min
37
- OpenStruct.new(
38
- date_beg: date_beg,
39
- date_end: date_end,
40
- days: (date_beg..date_end).count,
41
- day_rate: rate.day_rate,
42
- interests: amount * (date_beg..date_end).count * rate.day_rate
43
- )
29
+ interest_struct([from_date + 1.day, rate.from_date].max, [to_date, rate.to_date].min, amount, rate)
44
30
  end
45
31
  end
46
32
 
@@ -57,6 +43,25 @@ module Interests
57
43
  def blank_rate(date = BEGINNING_OF_COMPUTER_ERA, rate = 0.0)
58
44
  OpenStruct.new(date: date, rate: rate)
59
45
  end
46
+
47
+ def add_to_rates(prev_rate, rate)
48
+ from_date = prev_rate.date
49
+ to_date = rate.date - 1.day
50
+ days = (to_date - from_date).to_i
51
+ day_rate = prev_rate.rate.to_f / 365
52
+
53
+ @rates << OpenStruct.new(from_date: from_date, to_date: to_date, days: days, rate: prev_rate.rate, day_rate: day_rate)
54
+ end
55
+
56
+ def interest_struct(date_beg, date_end, amount, rate)
57
+ OpenStruct.new(
58
+ date_beg: date_beg,
59
+ date_end: date_end,
60
+ days: (date_beg..date_end).count,
61
+ day_rate: rate.day_rate,
62
+ interests: amount * (date_beg..date_end).count * rate.day_rate
63
+ )
64
+ end
60
65
  end
61
66
  end
62
67
  end
@@ -1,3 +1,3 @@
1
1
  module Interests
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interests
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
  - Alek Niemczyk