roi_calculator 2.1.0 → 2.2.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: fab4bba02a55b0a795a0b1453bd57a2858da7a05d8f767d5d85466b451eac16f
4
- data.tar.gz: e2f2c4c2340bdb57fb567935cc2954fa4b4c6f3712f7c57ed5541b0a8e926731
3
+ metadata.gz: 04b1f92abea56c262e66f32551040c1ec5e6bed8e42ae60cf1867d98b36fa7e0
4
+ data.tar.gz: 1d6d9209fe7152a599be99b6effa158696692d0faefd0e089a2b8352d478eed5
5
5
  SHA512:
6
- metadata.gz: 19dc72bde66f473b1fc81b34b8b24d5daa9884fde269675ce369047481bd4f8ce3e39774837c4d3f5d713185581c98de5f531dde9c75244eee6bf8f4b6128e51
7
- data.tar.gz: 198e1273641593b270c8ea70707f55bbd5eaad8df0ed814dfc5ebea7d4072a7f52cbf60659fcfb669d0e0292c5d52931e9e4d63309381324c9312d78eb5ebe2b
6
+ metadata.gz: e3ea5605bdbcdee6a856dc0c900db73c26d403ee2f75074fec8599abb481625021aa14c7bc1301a83f50956427677ce5547744bb6a2dc576615bf8058df1e814
7
+ data.tar.gz: 117182e61665f1550ca3676933f2ba97358eae87425ceb0cf0f2affbb9b21789ec95e5277f2234614c4eb21032f3af2a74953ae547ef8193c2a77f37cb71e7df
@@ -49,14 +49,16 @@ module ROI
49
49
 
50
50
  def format_gross_profit(scope_start, scope_end)
51
51
  return unless scope_start && scope_end
52
+
52
53
  total = scoped_rentabilities(scope_start, scope_end).sum do |line|
53
54
  line.try(:gross_profit) || 0
54
55
  end.round(2)
55
- total != 0 ? total : nil
56
+ total.zero? ? nil : total
56
57
  end
57
58
 
58
59
  def check_gaps_and_format(scope_start, scope_end)
59
60
  return unless scope_start >= start_date
61
+
60
62
  scoped_rentabilities(scope_start, scope_end).each do |line|
61
63
  return nil if line.try(:have_position) == false
62
64
  end
@@ -53,9 +53,7 @@ module ROI
53
53
  end
54
54
 
55
55
  def volatility(months_ago = nil)
56
- if months_ago
57
- start = (end_date - months_ago.months + 1.month).beginning_of_month
58
- end
56
+ start = (end_date - months_ago.months + 1.month).beginning_of_month if months_ago
59
57
  (volatility_in_window(nil, start).first || [])[1]
60
58
  end
61
59
 
@@ -73,9 +71,7 @@ module ROI
73
71
 
74
72
  def to_a
75
73
  dates_with_position.map do |date|
76
- if @rentabilities[date]
77
- [date.strftime('%Y-%m-%d'), @rentabilities[date].quota - 1]
78
- end
74
+ [date.strftime('%Y-%m-%d'), @rentabilities[date].quota - 1] if @rentabilities[date]
79
75
  end.compact
80
76
  end
81
77
 
@@ -15,8 +15,9 @@ module ROI
15
15
  end
16
16
 
17
17
  def months(amount, date = end_date)
18
- scoped_start = WorkDay.last_until((date - amount.month).end_of_month)
19
- scoped_end = adjust_end_date(date)
18
+ scoped_start =
19
+ WorkDay.last_until((date - (amount + 1).month).end_of_month)
20
+ scoped_end = adjust_end_date((date - 1.month).end_of_month)
20
21
  check_gaps_and_format(scoped_start, scoped_end)
21
22
  end
22
23
 
@@ -53,15 +54,14 @@ module ROI
53
54
 
54
55
  def format(start_date, end_date)
55
56
  scoped_start, scoped_end = rentabilities.values_at(start_date, end_date)
56
- if scoped_start && scoped_end
57
- ((scoped_end.quota / scoped_start.quota - 1) * 100).round(8)
58
- end
57
+ ((scoped_end.quota / scoped_start.quota - 1) * 100).round(8) if scoped_start && scoped_end
59
58
  end
60
59
 
61
60
  def check_gaps_and_format(scoped_start, scoped_end)
62
61
  local_start, local_end = rentabilities.values_at(scoped_start, scoped_end)
63
62
  return unless local_start && local_end
64
63
  return if skip_on_gap && gap?(local_start, local_end)
64
+
65
65
  format(scoped_start, scoped_end)
66
66
  end
67
67
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ROI
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
@@ -1,4 +1,3 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
3
  lib = File.expand_path('lib', __dir__)
@@ -6,18 +5,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'roi/version'
7
6
 
8
7
  Gem::Specification.new do |spec|
9
- spec.name = 'roi_calculator'
10
- spec.version = ROI::VERSION
11
- spec.authors = ['Adriano Bacha']
12
- spec.email = ['abacha@gmail.com']
8
+ spec.name = 'roi_calculator'
9
+ spec.version = ROI::VERSION
10
+ spec.authors = ['Adriano Bacha']
11
+ spec.email = ['abacha@gmail.com']
13
12
 
14
- spec.summary = 'Rentability and Gross Profit Calculations'
15
- spec.license = 'MIT'
13
+ spec.summary = 'Rentability and Gross Profit Calculations'
14
+ spec.license = 'MIT'
16
15
 
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
17
  f.match(%r{^(test|spec|features)/})
19
18
  end
20
- spec.require_paths = ['lib']
19
+ spec.require_paths = ['lib']
20
+ spec.required_ruby_version = '>= 2.5.0'
21
21
 
22
22
  spec.add_development_dependency 'bundler', '~> 1.13'
23
23
  spec.add_development_dependency 'rspec', '~> 3.0'
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.1.0
4
+ version: 2.2.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-20 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - ">="
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: 2.5.0
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="