roi_calculator 2.0.0 → 2.1.0

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: fc63825e0b9a50e16646d8a1b918ade35e0a507ae2b5da79a53d0b9759acd010
4
- data.tar.gz: 8e2cde87e2205d49f98f372c07797bbc2764699c9f77f5e07c8c44daac7178c1
3
+ metadata.gz: fab4bba02a55b0a795a0b1453bd57a2858da7a05d8f767d5d85466b451eac16f
4
+ data.tar.gz: e2f2c4c2340bdb57fb567935cc2954fa4b4c6f3712f7c57ed5541b0a8e926731
5
5
  SHA512:
6
- metadata.gz: edba4d7742f9cc1e5903a6d4d141e4be39a5cf9c21aa888e041cfa49953adf41819e41cb6b96785362602cfc48b8f3c9bceaf0b74334bfe8492e3f39dd7b1c11
7
- data.tar.gz: e09f232462b96ee5b2fc964447210322551b8c5b34959dfdbb7468cc4a7beb5a73c68fb8372b56e19961eda3c577cddea7db74dcfe0d6f563bc5fcf5b2927112
6
+ metadata.gz: 19dc72bde66f473b1fc81b34b8b24d5daa9884fde269675ce369047481bd4f8ce3e39774837c4d3f5d713185581c98de5f531dde9c75244eee6bf8f4b6128e51
7
+ data.tar.gz: 198e1273641593b270c8ea70707f55bbd5eaad8df0ed814dfc5ebea7d4072a7f52cbf60659fcfb669d0e0292c5d52931e9e4d63309381324c9312d78eb5ebe2b
@@ -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
@@ -3,7 +3,7 @@
3
3
  require 'roi/rentability'
4
4
  require 'roi/rentability_line'
5
5
  require 'roi/rentability_periods'
6
- require 'roi/financial_result'
6
+ require 'roi/gross_profit'
7
7
 
8
8
  module ROI
9
9
  end
@@ -5,7 +5,7 @@ require 'active_support'
5
5
  require 'active_support/core_ext/date'
6
6
 
7
7
  module ROI
8
- class FinancialResult
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
- format_financial(scope_start, end_date)
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
- format_financial(scope_start, end_date)
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
- format_financial(scope_start, scope_end)
35
+ format_gross_profit(scope_start, scope_end)
36
36
  end
37
37
 
38
38
  def portfolio
39
- format_financial(start_date, end_date)
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.date.between?(scope_start, scope_end)
46
+ line.reference_date.between?(scope_start, scope_end)
47
47
  end
48
48
  end
49
49
 
50
- def format_financial(scope_start, scope_end)
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(:daily_result) || 0
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
- format_financial(scope_start, scope_end)
63
+ format_gross_profit(scope_start, scope_end)
64
64
  end
65
65
  end
66
66
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'memoist'
4
- require 'roi/financial_result'
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 financial
38
- FinancialResult.new(rentabilities, start_date, end_date)
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.date.between?(start_date, end_date)
50
+ val.reference_date.between?(start_date, end_date)
51
51
  end
52
52
  filtered.map(&:rentability).compact
53
53
  end
@@ -2,10 +2,11 @@
2
2
 
3
3
  module ROI
4
4
  class RentabilityLine
5
- attr_reader :date, :rentability, :daily_result, :quota, :have_position
5
+ attr_reader :reference_date, :rentability,
6
+ :gross_profit, :quota, :have_position
6
7
 
7
- def initialize(date, rentability, quota, have_position)
8
- @date = date
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ROI
4
- VERSION = '2.0.0'
4
+ VERSION = '2.1.0'
5
5
  end
@@ -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 financial calculations'
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.0.0
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-06 00:00:00.000000000 Z
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/financial_result.rb
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.3
126
+ rubygems_version: 2.7.6
127
127
  signing_key:
128
128
  specification_version: 4
129
- summary: Rentability and financial calculations
129
+ summary: Rentability and Gross Profit Calculations
130
130
  test_files: []