roi_calculator 2.0.0 → 2.1.0
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 +4 -4
- data/bitbucket-pipelines.yml +1 -0
- data/lib/roi.rb +1 -1
- data/lib/roi/{financial_result.rb → gross_profit.rb} +9 -9
- data/lib/roi/rentability.rb +4 -4
- data/lib/roi/rentability_line.rb +4 -3
- data/lib/roi/rentability_periods.rb +10 -6
- data/lib/roi/version.rb +1 -1
- data/roi_calculator.gemspec +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fab4bba02a55b0a795a0b1453bd57a2858da7a05d8f767d5d85466b451eac16f
|
|
4
|
+
data.tar.gz: e2f2c4c2340bdb57fb567935cc2954fa4b4c6f3712f7c57ed5541b0a8e926731
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 19dc72bde66f473b1fc81b34b8b24d5daa9884fde269675ce369047481bd4f8ce3e39774837c4d3f5d713185581c98de5f531dde9c75244eee6bf8f4b6128e51
|
|
7
|
+
data.tar.gz: 198e1273641593b270c8ea70707f55bbd5eaad8df0ed814dfc5ebea7d4072a7f52cbf60659fcfb669d0e0292c5d52931e9e4d63309381324c9312d78eb5ebe2b
|
data/bitbucket-pipelines.yml
CHANGED
|
@@ -15,6 +15,7 @@ pipelines:
|
|
|
15
15
|
- step:
|
|
16
16
|
script:
|
|
17
17
|
- gem build roi_calculator.gemspec
|
|
18
|
+
- mkdir -p ~/.gem
|
|
18
19
|
- curl -u $RUBYGEMS_USERNAME:$RUBYGEMS_PASSWORD https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
|
|
19
20
|
- chmod 0600 ~/.gem/credentials
|
|
20
21
|
- gem push $(ls *.gem)
|
data/lib/roi.rb
CHANGED
|
@@ -5,7 +5,7 @@ require 'active_support'
|
|
|
5
5
|
require 'active_support/core_ext/date'
|
|
6
6
|
|
|
7
7
|
module ROI
|
|
8
|
-
class
|
|
8
|
+
class GrossProfit
|
|
9
9
|
attr_reader :start_date, :end_date, :rentabilities
|
|
10
10
|
|
|
11
11
|
def initialize(rentabilities, start_date, end_date)
|
|
@@ -16,7 +16,7 @@ module ROI
|
|
|
16
16
|
|
|
17
17
|
def current_month
|
|
18
18
|
scope_start = WorkDay.next_after(end_date.beginning_of_month, 0)
|
|
19
|
-
|
|
19
|
+
format_gross_profit(scope_start, end_date)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def months(amount)
|
|
@@ -26,31 +26,31 @@ module ROI
|
|
|
26
26
|
|
|
27
27
|
def current_year
|
|
28
28
|
scope_start = WorkDay.next_after(end_date.beginning_of_year, 0)
|
|
29
|
-
|
|
29
|
+
format_gross_profit(scope_start, end_date)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def years_ago(amount)
|
|
33
33
|
scope_end = (end_date - amount.year).end_of_year
|
|
34
34
|
scope_start = scope_end.beginning_of_year
|
|
35
|
-
|
|
35
|
+
format_gross_profit(scope_start, scope_end)
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def portfolio
|
|
39
|
-
|
|
39
|
+
format_gross_profit(start_date, end_date)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
private
|
|
43
43
|
|
|
44
44
|
def scoped_rentabilities(scope_start, scope_end)
|
|
45
45
|
rentabilities.values.select.each do |line|
|
|
46
|
-
line.
|
|
46
|
+
line.reference_date.between?(scope_start, scope_end)
|
|
47
47
|
end
|
|
48
48
|
end
|
|
49
49
|
|
|
50
|
-
def
|
|
50
|
+
def format_gross_profit(scope_start, scope_end)
|
|
51
51
|
return unless scope_start && scope_end
|
|
52
52
|
total = scoped_rentabilities(scope_start, scope_end).sum do |line|
|
|
53
|
-
line.try(:
|
|
53
|
+
line.try(:gross_profit) || 0
|
|
54
54
|
end.round(2)
|
|
55
55
|
total != 0 ? total : nil
|
|
56
56
|
end
|
|
@@ -60,7 +60,7 @@ module ROI
|
|
|
60
60
|
scoped_rentabilities(scope_start, scope_end).each do |line|
|
|
61
61
|
return nil if line.try(:have_position) == false
|
|
62
62
|
end
|
|
63
|
-
|
|
63
|
+
format_gross_profit(scope_start, scope_end)
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
end
|
data/lib/roi/rentability.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'memoist'
|
|
4
|
-
require 'roi/
|
|
4
|
+
require 'roi/gross_profit'
|
|
5
5
|
require 'roi/rentability_periods'
|
|
6
6
|
require 'math_util'
|
|
7
7
|
require 'active_support'
|
|
@@ -34,8 +34,8 @@ module ROI
|
|
|
34
34
|
self
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
def
|
|
38
|
-
|
|
37
|
+
def gross_profit
|
|
38
|
+
GrossProfit.new(rentabilities, start_date, end_date)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def dates_with_position
|
|
@@ -47,7 +47,7 @@ module ROI
|
|
|
47
47
|
end_date ||= @end_date
|
|
48
48
|
|
|
49
49
|
filtered = @rentabilities.values.select do |val|
|
|
50
|
-
val.
|
|
50
|
+
val.reference_date.between?(start_date, end_date)
|
|
51
51
|
end
|
|
52
52
|
filtered.map(&:rentability).compact
|
|
53
53
|
end
|
data/lib/roi/rentability_line.rb
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module ROI
|
|
4
4
|
class RentabilityLine
|
|
5
|
-
attr_reader :
|
|
5
|
+
attr_reader :reference_date, :rentability,
|
|
6
|
+
:gross_profit, :quota, :have_position
|
|
6
7
|
|
|
7
|
-
def initialize(
|
|
8
|
-
@
|
|
8
|
+
def initialize(reference_date, rentability, quota, have_position)
|
|
9
|
+
@reference_date = reference_date
|
|
9
10
|
@rentability = rentability
|
|
10
11
|
@quota = quota
|
|
11
12
|
@have_position = have_position
|
|
@@ -61,13 +61,17 @@ module ROI
|
|
|
61
61
|
def check_gaps_and_format(scoped_start, scoped_end)
|
|
62
62
|
local_start, local_end = rentabilities.values_at(scoped_start, scoped_end)
|
|
63
63
|
return unless local_start && local_end
|
|
64
|
-
if skip_on_gap
|
|
65
|
-
rentabilities.each_value do |line|
|
|
66
|
-
return nil if line.date.between?(local_start.date, local_end.date) &&
|
|
67
|
-
!line.have_position
|
|
68
|
-
end
|
|
69
|
-
end
|
|
64
|
+
return if skip_on_gap && gap?(local_start, local_end)
|
|
70
65
|
format(scoped_start, scoped_end)
|
|
71
66
|
end
|
|
67
|
+
|
|
68
|
+
def gap?(start_date, end_date)
|
|
69
|
+
gap = rentabilities.values.detect do |line|
|
|
70
|
+
line.reference_date.between?(
|
|
71
|
+
start_date.reference_date, end_date.reference_date
|
|
72
|
+
) && !line.have_position
|
|
73
|
+
end
|
|
74
|
+
!gap.nil?
|
|
75
|
+
end
|
|
72
76
|
end
|
|
73
77
|
end
|
data/lib/roi/version.rb
CHANGED
data/roi_calculator.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
|
11
11
|
spec.authors = ['Adriano Bacha']
|
|
12
12
|
spec.email = ['abacha@gmail.com']
|
|
13
13
|
|
|
14
|
-
spec.summary = 'Rentability and
|
|
14
|
+
spec.summary = 'Rentability and Gross Profit Calculations'
|
|
15
15
|
spec.license = 'MIT'
|
|
16
16
|
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roi_calculator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Adriano Bacha
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-04-
|
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -97,7 +97,7 @@ files:
|
|
|
97
97
|
- README.md
|
|
98
98
|
- bitbucket-pipelines.yml
|
|
99
99
|
- lib/roi.rb
|
|
100
|
-
- lib/roi/
|
|
100
|
+
- lib/roi/gross_profit.rb
|
|
101
101
|
- lib/roi/rentability.rb
|
|
102
102
|
- lib/roi/rentability_line.rb
|
|
103
103
|
- lib/roi/rentability_periods.rb
|
|
@@ -123,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
123
|
version: '0'
|
|
124
124
|
requirements: []
|
|
125
125
|
rubyforge_project:
|
|
126
|
-
rubygems_version: 2.7.
|
|
126
|
+
rubygems_version: 2.7.6
|
|
127
127
|
signing_key:
|
|
128
128
|
specification_version: 4
|
|
129
|
-
summary: Rentability and
|
|
129
|
+
summary: Rentability and Gross Profit Calculations
|
|
130
130
|
test_files: []
|