business-period 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c8b9e6bd6acbc4269243b4f104fdfece8611679
4
- data.tar.gz: 0ac9ddf3aa480b1113e37e7c0ebe6085758e4603
3
+ metadata.gz: 6098b1a6ef4926e03bce624585c037eaf04cbc67
4
+ data.tar.gz: 4e3844c7a1cfae8573cb5afe08fd6aa24f3fbc39
5
5
  SHA512:
6
- metadata.gz: d14c9cdd5e7506d0abe73b7da1ba331089b04bd64fb5efb7b5623c2bcdb6f7113e9aecefabbfc3fd4b5090edace43b8176ced863e183d71612dba119ef14f80d
7
- data.tar.gz: 2ffbacf3893af7cdf118bed8d487e1d5e49c0243b15e2e3e0556e36226cfeb070587561a53f5652bfa020de2d400411f024086e1797aa8bf58268780b35f7801
6
+ metadata.gz: 10251873c3359a732d0bf338a61ce91ab254ab0bd3c71985b849f1b9e97ce57b6adee8257cf850951065a7f24ea8957ca2a493d2215599d97b2d60fb68b5639c
7
+ data.tar.gz: 61c2faa61df87564ea89311937158cb7515f70f73a31d05d2138314946369996bc3727fd8d5cc0b4465bd6e3073763dc500631bc9de3cc52ab49988a0d50500b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- business-period (0.1.2)
4
+ business-period (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -6,11 +6,12 @@ module BusinessPeriod
6
6
  @config ||= Config
7
7
  end
8
8
 
9
- def calculate_period(to_date)
9
+ def calculate_period(to_date, options = nil)
10
10
  magic_number = 15 - config.work_days.size
11
11
  days_to_add = days_to_seconds(to_date * magic_number)
12
- finish = Time.now + days_to_add
13
- Time.now.to_date..finish.to_date
12
+ start_date = options[:primary_day] || Time.now
13
+ finish = start_date + days_to_add
14
+ start_date.to_date..finish.to_date
14
15
  end
15
16
 
16
17
  def holidays
@@ -2,17 +2,18 @@
2
2
 
3
3
  module BusinessPeriod
4
4
  class Days < Base
5
- def self.call(from_date:, to_date:)
6
- new.perform(from_date, to_date)
5
+ def self.call(from_date:, to_date:, options: {})
6
+ new.perform(from_date, to_date, options)
7
7
  end
8
8
 
9
- def perform(from_date, to_date)
9
+ def perform(from_date, to_date, options)
10
10
  @from_date = from_date
11
11
  @to_date = to_date
12
+ @options = options
12
13
 
13
14
  return [] unless valid_params
14
15
 
15
- period = calculate_period(@to_date)
16
+ period = calculate_period(@to_date, @options)
16
17
  days = business_days(period)
17
18
  result = extract_holidays(days).compact
18
19
 
@@ -25,11 +26,22 @@ module BusinessPeriod
25
26
  private
26
27
 
27
28
  def valid_params
28
- @from_date.is_a?(Integer) && @to_date.is_a?(Integer) &&
29
+ valid_options &&
30
+ @from_date.is_a?(Integer) && @to_date.is_a?(Integer) &&
29
31
  @from_date >= 0 && @to_date >= 0 &&
30
32
  (@from_date <= @to_date)
31
33
  end
32
34
 
35
+ def valid_options
36
+ @options ? primary_day_present? : true
37
+ end
38
+
39
+ def primary_day_present?
40
+ return unless @options.is_a?(Hash)
41
+
42
+ @options[:primary_day] ? (@options[:primary_day].methods.include? :strftime) : true
43
+ end
44
+
33
45
  def extract_holidays(days)
34
46
  days.map.with_index do |day, idx|
35
47
  next unless holidays[day[:day].month]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BusinessPeriod
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business-period
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - matas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-17 00:00:00.000000000 Z
11
+ date: 2018-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec