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 +4 -4
- data/README.md +1 -1
- data/lib/interests/calculator.rb +21 -16
- data/lib/interests/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f68e0d0ff75ce39417b1d340243d991deaabe1bd
|
4
|
+
data.tar.gz: 6a1a2986ff1dd94b9964db3cbdda96ae9e149ffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae2fe645dd49127775adbdc0250fc558af87828960cb037f3ead28cdc1282355aad3e3ea5858c7624e0b6ca7be7ab17c5322c958dedbf945bfa482514f236ed2
|
7
|
+
data.tar.gz: f665bac846df25cb325f352108cfaf2c1485aa5b354d4c48bb4ba0793cade5c24effd9ed6016c1d6b1c228c9258095188c9524651b54e5562d5c012be29be185
|
data/README.md
CHANGED
data/lib/interests/calculator.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/interests/version.rb
CHANGED