biz 1.3.3 → 1.3.4

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
  SHA1:
3
- metadata.gz: 14ced23b25b1eada2cc2120be433aa949741f16e
4
- data.tar.gz: b2f797726e49278c6388bce71f7b85d04f435d48
3
+ metadata.gz: 17b73c0b4db75f5474b6ea1ffb504295aa9d5b33
4
+ data.tar.gz: 760ad3e6cac89007667985a38e6d9cddd0587c3a
5
5
  SHA512:
6
- metadata.gz: bb3d77c08bc245fb5220ed69d71809cc52f27379c0d83a325288c2a41f1c4e78e0200ce965e3657694b52aa4967571f59afe841e3f0c9904c8d3fe6358f6bf21
7
- data.tar.gz: 0b2bb9dc20437369b2c6b760baa87bc381d80640bdc9db7079ddd96105d0b9e4dd222c5bf1769af203af6a3e4e4e6533e98becaa83bec6ac286ac147fd057586
6
+ metadata.gz: 7559524dfaf3702887f4250e7a899114fb52d94a28cb662b2680abc0ad94c073b2f6d20b719d00023eb54079f9418ca04e51ed502945c8ec2cebbbaccea91716
7
+ data.tar.gz: fc2f54dcd99a298ff208ea53978106424b1543615f9c30c82e85abe2759d4cbb9047f758c017df0ade11c4d303f00872ef682cd7298635ec6a8c37827ba3ad54
data/README.md CHANGED
@@ -171,7 +171,7 @@ To open a console with the gem and sample schedule loaded:
171
171
 
172
172
  ## Copyright and license
173
173
 
174
- Copyright 2015 Zendesk
174
+ Copyright 2015-16 Zendesk
175
175
 
176
176
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use
177
177
  this gem except in compliance with the License.
data/lib/biz.rb CHANGED
@@ -3,10 +3,7 @@ require 'delegate'
3
3
  require 'forwardable'
4
4
  require 'set'
5
5
 
6
- require 'abstract_type'
7
6
  require 'clavius'
8
- require 'equalizer'
9
- require 'memoizable'
10
7
  require 'tzinfo'
11
8
 
12
9
  module Biz
@@ -4,7 +4,10 @@ module Biz
4
4
 
5
5
  def initialize(schedule, calculation_period)
6
6
  super(
7
- schedule.periods.after(calculation_period.start_time).timeline
7
+ schedule
8
+ .periods
9
+ .after(calculation_period.start_time)
10
+ .timeline
8
11
  .until(calculation_period.end_time)
9
12
  .map(&:duration)
10
13
  .reduce(Duration.new(0), :+)
@@ -4,8 +4,6 @@ module Biz
4
4
 
5
5
  UNITS = Set.new(%i[second seconds minute minutes hour hours day days])
6
6
 
7
- include AbstractType
8
-
9
7
  def self.with_unit(schedule, scalar, unit)
10
8
  unless UNITS.include?(unit)
11
9
  fail ArgumentError, 'The unit is not supported.'
@@ -23,9 +21,6 @@ module Biz
23
21
  @scalar = scalar
24
22
  end
25
23
 
26
- abstract_method :before,
27
- :after
28
-
29
24
  protected
30
25
 
31
26
  attr_reader :schedule,
@@ -39,7 +34,8 @@ module Biz
39
34
 
40
35
  [
41
36
  *%i[second seconds minute minutes hour hours].map { |unit|
42
- const_set(unit.to_s.capitalize,
37
+ const_set(
38
+ unit.to_s.capitalize,
43
39
  Class.new(self) do
44
40
  def before(time)
45
41
  timeline(:before, time).last.start_time
@@ -63,7 +59,8 @@ module Biz
63
59
  )
64
60
  },
65
61
  *%i[day days].map { |unit|
66
- const_set(unit.to_s.capitalize,
62
+ const_set(
63
+ unit.to_s.capitalize,
67
64
  Class.new(self) do
68
65
  def before(time)
69
66
  periods(:before, time).first.end_time
@@ -1,8 +1,6 @@
1
1
  module Biz
2
2
  class Configuration
3
3
 
4
- include Memoizable
5
-
6
4
  def initialize
7
5
  @raw = Raw.new.tap do |raw| yield raw if block_given? end
8
6
 
@@ -10,21 +8,27 @@ module Biz
10
8
  end
11
9
 
12
10
  def intervals
13
- raw.hours.flat_map { |weekday, hours|
14
- weekday_intervals(weekday, hours)
15
- }.sort_by(&:start_time)
11
+ @intervals ||= begin
12
+ raw
13
+ .hours
14
+ .flat_map { |weekday, hours| weekday_intervals(weekday, hours) }
15
+ .sort_by(&:start_time)
16
+ .freeze
17
+ end
16
18
  end
17
19
 
18
20
  def holidays
19
- raw.holidays.map { |date| Holiday.new(date, time_zone) }
21
+ @holidays ||= begin
22
+ raw.holidays.map { |date| Holiday.new(date, time_zone) }.freeze
23
+ end
20
24
  end
21
25
 
22
26
  def time_zone
23
- TZInfo::TimezoneProxy.new(raw.time_zone)
27
+ @time_zone ||= TZInfo::TimezoneProxy.new(raw.time_zone)
24
28
  end
25
29
 
26
30
  def weekdays
27
- raw.hours.keys.to_set
31
+ @weekdays ||= raw.hours.keys.to_set.freeze
28
32
  end
29
33
 
30
34
  protected
@@ -49,10 +53,6 @@ module Biz
49
53
  }
50
54
  end
51
55
 
52
- memoize :intervals,
53
- :holidays,
54
- :weekdays
55
-
56
56
  Raw = Struct.new(:hours, :holidays, :time_zone) do
57
57
  module Default
58
58
  HOURS = {
@@ -61,9 +61,10 @@ module Biz
61
61
  wed: {'09:00' => '17:00'},
62
62
  thu: {'09:00' => '17:00'},
63
63
  fri: {'09:00' => '17:00'}
64
- }
65
- HOLIDAYS = []
66
- TIME_ZONE = 'Etc/UTC'
64
+ }.freeze
65
+
66
+ HOLIDAYS = [].freeze
67
+ TIME_ZONE = 'Etc/UTC'.freeze
67
68
  end
68
69
 
69
70
  def initialize(*)
@@ -15,7 +15,7 @@ module Biz
15
15
 
16
16
  class << self
17
17
 
18
- alias_method :since_epoch, :from_time
18
+ alias since_epoch from_time
19
19
 
20
20
  end
21
21
 
@@ -1,7 +1,7 @@
1
1
  module Biz
2
2
  class DayOfWeek
3
3
 
4
- SYMBOLS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat]
4
+ SYMBOLS = %i[sun mon tue wed thu fri sat].freeze
5
5
 
6
6
  def self.from_time(time)
7
7
  DAYS.fetch(time.wday)
@@ -21,7 +21,7 @@ module Biz
21
21
 
22
22
  class << self
23
23
 
24
- alias_method :from_date, :from_time
24
+ alias from_date from_time
25
25
 
26
26
  end
27
27
 
@@ -67,7 +67,7 @@ module Biz
67
67
  THURSDAY = new(4),
68
68
  FRIDAY = new(5),
69
69
  SATURDAY = new(6)
70
- ]
70
+ ].freeze
71
71
 
72
72
  WEEKDAYS = [
73
73
  MONDAY,
@@ -75,7 +75,7 @@ module Biz
75
75
  WEDNESDAY,
76
76
  THURSDAY,
77
77
  FRIDAY
78
- ]
78
+ ].freeze
79
79
 
80
80
  end
81
81
  end
@@ -4,7 +4,7 @@ module Biz
4
4
  VALID_SECONDS = 0..Time::SECONDS_IN_DAY
5
5
 
6
6
  module Timestamp
7
- FORMAT = '%02d:%02d'
7
+ FORMAT = '%02d:%02d'.freeze
8
8
  PATTERN = /\A(?<hour>\d{2}):(?<minute>\d{2})(:?(?<second>\d{2}))?\Z/
9
9
  end
10
10
 
@@ -44,13 +44,13 @@ module Biz
44
44
  MIDNIGHT
45
45
  end
46
46
 
47
- alias_method :am, :midnight
47
+ alias am midnight
48
48
 
49
49
  def noon
50
50
  NOON
51
51
  end
52
52
 
53
- alias_method :pm, :noon
53
+ alias pm noon
54
54
 
55
55
  def endnight
56
56
  ENDNIGHT
@@ -1,7 +1,6 @@
1
1
  module Biz
2
2
  class Duration
3
3
 
4
- include Equalizer.new(:seconds)
5
4
  include Comparable
6
5
 
7
6
  extend Forwardable
@@ -12,19 +11,19 @@ module Biz
12
11
  new(seconds)
13
12
  end
14
13
 
15
- alias_method :second, :seconds
14
+ alias second seconds
16
15
 
17
16
  def minutes(minutes)
18
17
  new(minutes * Time::SECONDS_IN_MINUTE)
19
18
  end
20
19
 
21
- alias_method :minute, :minutes
20
+ alias minute minutes
22
21
 
23
22
  def hours(hours)
24
23
  new(hours * Time::SECONDS_IN_HOUR)
25
24
  end
26
25
 
27
- alias_method :hour, :hours
26
+ alias hour hours
28
27
 
29
28
  end
30
29
 
@@ -1,8 +1,6 @@
1
1
  module Biz
2
2
  class Holiday
3
3
 
4
- include Equalizer.new(:date, :time_zone)
5
-
6
4
  attr_reader :date,
7
5
  :time_zone
8
6
 
@@ -22,7 +20,7 @@ module Biz
22
20
  )
23
21
  end
24
22
 
25
- alias_method :to_date, :date
23
+ alias to_date date
26
24
 
27
25
  end
28
26
  end
@@ -1,8 +1,6 @@
1
1
  module Biz
2
2
  class Interval
3
3
 
4
- include Equalizer.new(:start_time, :end_time, :time_zone)
5
-
6
4
  attr_reader :start_time,
7
5
  :end_time,
8
6
  :time_zone
@@ -25,17 +25,16 @@ module Biz
25
25
  private
26
26
 
27
27
  def periods
28
- weeks.lazy.flat_map { |week|
29
- business_periods(week)
30
- }.select { |business_period|
31
- relevant?(business_period)
32
- }.map { |business_period|
33
- business_period & boundary
34
- }.reject { |business_period|
35
- schedule.holidays.any? { |holiday|
36
- holiday.contains?(business_period.start_time)
28
+ weeks
29
+ .lazy
30
+ .flat_map { |week| business_periods(week) }
31
+ .select { |business_period| relevant?(business_period) }
32
+ .map { |business_period| business_period & boundary }
33
+ .reject { |business_period|
34
+ schedule.holidays.any? { |holiday|
35
+ holiday.contains?(business_period.start_time)
36
+ }
37
37
  }
38
- }
39
38
  end
40
39
 
41
40
  def business_periods(week)
@@ -22,7 +22,7 @@ module Biz
22
22
  Dates.new(self)
23
23
  end
24
24
 
25
- alias_method :date, :dates
25
+ alias date dates
26
26
 
27
27
  def time(scalar, unit)
28
28
  Calculation::ForDuration.with_unit(self, scalar, unit)
@@ -40,7 +40,7 @@ module Biz
40
40
  Calculation::OnHoliday.new(self, time).result
41
41
  end
42
42
 
43
- alias_method :business_hours?, :in_hours?
43
+ alias business_hours? in_hours?
44
44
 
45
45
  def in_zone
46
46
  Time.new(time_zone)
@@ -1,8 +1,6 @@
1
1
  module Biz
2
2
  class TimeSegment
3
3
 
4
- include Equalizer.new(:start_time, :end_time)
5
-
6
4
  def self.before(time)
7
5
  new(Time::BIG_BANG, time)
8
6
  end
@@ -9,13 +9,13 @@ module Biz
9
9
  def until(terminus)
10
10
  return enum_for(:until, terminus) unless block_given?
11
11
 
12
- periods.map { |period|
13
- period & comparison_period(period, terminus)
14
- }.each do |period|
15
- yield period unless period.empty?
12
+ periods
13
+ .map { |period| period & comparison_period(period, terminus) }
14
+ .each do |period|
15
+ yield period unless period.empty?
16
16
 
17
- break if occurred?(period, terminus)
18
- end
17
+ break if occurred?(period, terminus)
18
+ end
19
19
  end
20
20
 
21
21
  def for(duration)
@@ -23,15 +23,15 @@ module Biz
23
23
 
24
24
  remaining = duration
25
25
 
26
- periods.map { |period|
27
- period & duration_period(period, remaining)
28
- }.each do |period|
29
- yield period unless period.empty?
26
+ periods
27
+ .map { |period| period & duration_period(period, remaining) }
28
+ .each do |period|
29
+ yield period unless period.empty?
30
30
 
31
- remaining -= period.duration
31
+ remaining -= period.duration
32
32
 
33
- break unless remaining.positive?
34
- end
33
+ break unless remaining.positive?
34
+ end
35
35
  end
36
36
 
37
37
  protected
@@ -37,14 +37,16 @@ module Biz
37
37
 
38
38
  end
39
39
 
40
- RULES = Set.new([
41
- Rule.new('Hours must be hash-like.') { |raw|
42
- raw.hours.respond_to?(:to_h)
43
- },
44
- Rule.new('Hours must be provided.') { |raw|
45
- raw.hours.to_h.any?
46
- }
47
- ])
40
+ RULES = Set.new(
41
+ [
42
+ Rule.new('Hours must be hash-like.') { |raw|
43
+ raw.hours.respond_to?(:to_h)
44
+ },
45
+ Rule.new('Hours must be provided.') { |raw|
46
+ raw.hours.to_h.any?
47
+ }
48
+ ]
49
+ )
48
50
 
49
51
  end
50
52
  end
@@ -1,3 +1,3 @@
1
1
  module Biz
2
- VERSION = '1.3.3'
2
+ VERSION = '1.3.4'.freeze
3
3
  end
@@ -15,7 +15,7 @@ module Biz
15
15
 
16
16
  class << self
17
17
 
18
- alias_method :since_epoch, :from_time
18
+ alias since_epoch from_time
19
19
 
20
20
  end
21
21
 
@@ -14,7 +14,7 @@ module Biz
14
14
  End.new(week_minute)
15
15
  end
16
16
 
17
- alias_method :build, :start
17
+ alias build start
18
18
 
19
19
  end
20
20
  end
@@ -2,9 +2,7 @@ module Biz
2
2
  module WeekTime
3
3
  class Abstract
4
4
 
5
- include AbstractType
6
5
  include Comparable
7
- include Memoizable
8
6
 
9
7
  extend Forwardable
10
8
 
@@ -49,8 +47,6 @@ module Biz
49
47
  to_int
50
48
  ] => :week_minute
51
49
 
52
- abstract_method :day_time
53
-
54
50
  protected
55
51
 
56
52
  def <=>(other)
@@ -71,8 +67,6 @@ module Biz
71
67
  )
72
68
  end
73
69
 
74
- abstract_method :day_of_week
75
-
76
70
  end
77
71
  end
78
72
  end
@@ -3,18 +3,17 @@ module Biz
3
3
  class End < Abstract
4
4
 
5
5
  def day_time
6
- DayTime.from_minute(day_of_week.day_minute(week_minute))
6
+ @day_time ||= DayTime.from_minute(day_of_week.day_minute(week_minute))
7
7
  end
8
8
 
9
9
  private
10
10
 
11
11
  def day_of_week
12
- DayOfWeek::DAYS.find { |day| day.contains?(week_minute) }
12
+ @day_of_week ||= begin
13
+ DayOfWeek::DAYS.find { |day| day.contains?(week_minute) }
14
+ end
13
15
  end
14
16
 
15
- memoize :day_of_week,
16
- :day_time
17
-
18
17
  end
19
18
  end
20
19
  end
@@ -3,20 +3,19 @@ module Biz
3
3
  class Start < Abstract
4
4
 
5
5
  def day_time
6
- DayTime.from_minute(week_minute % Time::MINUTES_IN_DAY)
6
+ @day_time ||= DayTime.from_minute(week_minute % Time::MINUTES_IN_DAY)
7
7
  end
8
8
 
9
9
  private
10
10
 
11
11
  def day_of_week
12
- DayOfWeek::DAYS.fetch(
13
- week_minute / Time::MINUTES_IN_DAY % Time::DAYS_IN_WEEK
14
- )
12
+ @day_of_week ||= begin
13
+ DayOfWeek::DAYS.fetch(
14
+ week_minute / Time::MINUTES_IN_DAY % Time::DAYS_IN_WEEK
15
+ )
16
+ end
15
17
  end
16
18
 
17
- memoize :day_of_week,
18
- :day_time
19
-
20
19
  end
21
20
  end
22
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: biz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Little
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-19 00:00:00.000000000 Z
12
+ date: 2016-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: abstract_type
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: 0.0.0
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: 0.0.0
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: clavius
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -39,34 +25,6 @@ dependencies:
39
25
  - - "~>"
40
26
  - !ruby/object:Gem::Version
41
27
  version: '1.0'
42
- - !ruby/object:Gem::Dependency
43
- name: equalizer
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 0.0.0
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 0.0.0
56
- - !ruby/object:Gem::Dependency
57
- name: memoizable
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: 0.4.0
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 0.4.0
70
28
  - !ruby/object:Gem::Dependency
71
29
  name: tzinfo
72
30
  requirement: !ruby/object:Gem::Requirement
@@ -183,3 +141,4 @@ signing_key:
183
141
  specification_version: 4
184
142
  summary: Business hours calculations
185
143
  test_files: []
144
+ has_rdoc: