biz 1.3.0 → 1.3.1

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: 6fce08ec05e3857a5344b99ecd544e182ad1a877
4
- data.tar.gz: db94653d507d2be6c3b6b2ea6ba12ea13c57afd8
3
+ metadata.gz: 89a15e7c6f5161b0a1b5e1132b1f9b4cc0b2e7c4
4
+ data.tar.gz: ff36ac8b0a4f6d2f6971c6fb8beaf36df09ac251
5
5
  SHA512:
6
- metadata.gz: a55c8051f5980fc7ec592631bf597f72b66699820df7de97fab3b2dbffaab7a1db6bb81c4a59c5ec4794bf62a40b24e282c319a6a057ffab0612957c3a9d96d7
7
- data.tar.gz: bac1486b182762a98ba869643e8271fb3cedc93a69f34579560f91b9e933125b5a5fafb085ad9002a05c027bba359259e431b4513db54bdca11cfc865ec2f384
6
+ metadata.gz: 71f2ab477908d44026f15f4a10a09dd8ba6396ae871e998f29ebe58b15c1f2919959b8bf1fc11f648ab726050f9aa16272ccf5ce52f9b87ca73a8444485cc150
7
+ data.tar.gz: 93a8e96e6e8e3df4957cb66844b1d0b253db0e300cde2deec5cb6a01b73a2dcfbd179b26d7943687129968cbca559782f6e27213992c5023071cb26b13b6ce71
data/lib/biz.rb CHANGED
@@ -51,6 +51,7 @@ require 'biz/day'
51
51
  require 'biz/day_of_week'
52
52
  require 'biz/day_time'
53
53
  require 'biz/duration'
54
+ require 'biz/error'
54
55
  require 'biz/holiday'
55
56
  require 'biz/interval'
56
57
  require 'biz/periods'
@@ -59,4 +60,5 @@ require 'biz/timeline'
59
60
  require 'biz/time_segment'
60
61
  require 'biz/week'
61
62
  require 'biz/week_time'
63
+ require 'biz/validation'
62
64
  require 'biz/version'
@@ -5,6 +5,8 @@ module Biz
5
5
 
6
6
  def initialize
7
7
  @raw = Raw.new.tap do |raw| yield raw if block_given? end
8
+
9
+ Validation.perform(raw)
8
10
  end
9
11
 
10
12
  def intervals
@@ -0,0 +1,7 @@
1
+ module Biz
2
+ class Error < StandardError
3
+
4
+ Configuration = Class.new(self)
5
+
6
+ end
7
+ end
@@ -4,7 +4,7 @@ module Biz
4
4
  MINUTE = 60
5
5
  HOUR = 60 * MINUTE
6
6
  DAY = 24 * HOUR
7
- WEEK = 7 * DAY
7
+ WEEK = 7 * DAY
8
8
 
9
9
  MINUTES_IN_HOUR = 60
10
10
  HOURS_IN_DAY = 24
@@ -0,0 +1,50 @@
1
+ module Biz
2
+ class Validation
3
+
4
+ def self.perform(raw)
5
+ new(raw).perform
6
+ end
7
+
8
+ def initialize(raw)
9
+ @raw = raw
10
+ end
11
+
12
+ def perform
13
+ RULES.each do |rule| rule.check(raw) end
14
+
15
+ self
16
+ end
17
+
18
+ protected
19
+
20
+ attr_reader :raw
21
+
22
+ class Rule
23
+
24
+ def initialize(message, &condition)
25
+ @message = message
26
+ @condition = condition
27
+ end
28
+
29
+ def check(raw)
30
+ fail Error::Configuration, message unless condition.call(raw)
31
+ end
32
+
33
+ protected
34
+
35
+ attr_reader :message,
36
+ :condition
37
+
38
+ end
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
+ ])
48
+
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Biz
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  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.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Little
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-29 00:00:00.000000000 Z
12
+ date: 2015-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: abstract_type
@@ -135,6 +135,7 @@ files:
135
135
  - lib/biz/day_of_week.rb
136
136
  - lib/biz/day_time.rb
137
137
  - lib/biz/duration.rb
138
+ - lib/biz/error.rb
138
139
  - lib/biz/holiday.rb
139
140
  - lib/biz/interval.rb
140
141
  - lib/biz/periods.rb
@@ -150,6 +151,7 @@ files:
150
151
  - lib/biz/timeline/backward.rb
151
152
  - lib/biz/timeline/forward.rb
152
153
  - lib/biz/timeline/proxy.rb
154
+ - lib/biz/validation.rb
153
155
  - lib/biz/version.rb
154
156
  - lib/biz/week.rb
155
157
  - lib/biz/week_time.rb
@@ -176,9 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
178
  version: '0'
177
179
  requirements: []
178
180
  rubyforge_project:
179
- rubygems_version: 2.4.5
181
+ rubygems_version: 2.4.5.1
180
182
  signing_key:
181
183
  specification_version: 4
182
184
  summary: Business hours calculations
183
185
  test_files: []
184
- has_rdoc: