in_business 0.0.2 → 0.0.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0093d22a222575126431f79ef14a55d1907f3715
4
+ data.tar.gz: 3c603101a07ff91fb9029d534cecf6a0bad21b19
5
+ SHA512:
6
+ metadata.gz: a773aac49e1cc4defb1295611b5f7218689459941c55503668468d98536e4795e00e41305a270506b125ef050f976d70977dc155ea385bdc3914c9116209aeca
7
+ data.tar.gz: 307f8cd6ffa0b9b7f5665c27d82af3b4f492f2fb78503cbdd801dded93050b1d5e38affbf6bcacc95dc9ea66c41b1fa68b6a1777207e0bf3999192f05654e72d
data/README.md CHANGED
@@ -24,10 +24,11 @@ gem.
24
24
  ## Usage
25
25
 
26
26
  ```ruby
27
- InBusiness.open? DateTime.now # => nil (since we've not set any hours yet!)
27
+ InBusiness.open? # => nil (since we've not set any hours yet!)
28
28
 
29
29
  # We want to be open 9am til 6pm on a Monday
30
30
  InBusiness.hours.monday = "09:00".."18:00"
31
+ InBusiness.open? # Returns true if it's Monday between 9am and 6pm, false otherwise
31
32
  InBusiness.open? DateTime.parse('10am Monday') # => true
32
33
  InBusiness.closed? DateTime.parse('9pm Monday') # => true
33
34
 
data/lib/in_business.rb CHANGED
@@ -1,69 +1,76 @@
1
1
  require 'ostruct'
2
2
  require 'active_support/core_ext'
3
+ require 'active_support/concern'
3
4
 
4
5
  module InBusiness
6
+ extend ActiveSupport::Concern
5
7
 
6
- @holidays = []
7
- @hours = OpenStruct.new
8
-
9
- def self.holidays
10
- @holidays
8
+ included do
9
+ include InstanceMethods
11
10
  end
12
11
 
13
- def self.holidays=(array)
14
- @holidays = array
15
- end
12
+ module InstanceMethods
13
+ def holidays
14
+ @holidays ||= []
15
+ end
16
16
 
17
- def self.hours
18
- @hours
19
- end
17
+ def holidays=(array)
18
+ @holidays = array
19
+ end
20
20
 
21
- def self.hours=(hash)
22
- @hours = OpenStruct.new(hash)
23
- end
21
+ def hours
22
+ @hours ||= OpenStruct.new
23
+ end
24
24
 
25
- def self.reset
26
- # Used for clearing the state of InBusiness between specs
27
- @holidays = []
28
- @hours = OpenStruct.new
29
- true
30
- end
25
+ def hours=(hash)
26
+ @hours = OpenStruct.new(hash)
27
+ end
28
+
29
+ def reset
30
+ # Used for clearing the state of InBusiness between specs
31
+ self.holidays = []
32
+ self.hours = {}
33
+ true
34
+ end
31
35
 
32
- def self.open?(datetime)
33
-
34
- # If this is included in the list of holidays, return false
35
- return false if is_holiday? datetime
36
+ def open?(datetime=DateTime.now)
37
+
38
+ # If this is included in the list of holidays, return false
39
+ return false if is_holiday? datetime
36
40
 
37
- # If we don't know the opening hours for datetime's day, assume we're closed
38
- return false unless hours.send(days[datetime.wday.to_s].to_sym)
41
+ # If we don't know the opening hours for datetime's day, assume we're closed
42
+ return false unless hours.send(days[datetime.wday.to_s].to_sym)
39
43
 
40
- # We have opening hours, so check if the current time is within them
41
- if !hours.send(days[datetime.wday.to_s].to_sym).include? datetime.strftime("%H:%M")
42
- return false
43
- end
44
+ # We have opening hours, so check if the current time is within them
45
+ if !hours.send(days[datetime.wday.to_s].to_sym).cover? datetime.strftime("%H:%M")
46
+ return false
47
+ end
44
48
 
45
- true # It's not not open, so it must be open ;)
46
- end
49
+ true # It's not not open, so it must be open ;)
50
+ end
47
51
 
48
- def self.closed?(datetime)
49
- !open?(datetime)
50
- end
52
+ def closed?(datetime=DateTime.now)
53
+ !open?(datetime)
54
+ end
51
55
 
52
- def self.is_holiday?(date)
53
- @holidays.include? date.to_date
54
- end
56
+ def is_holiday?(date=DateTime.now)
57
+ holidays.include? date.to_date
58
+ end
55
59
 
56
- # Maps values of [DateTime/Date/Time]#wday to English days
57
- def self.days
58
- {
59
- "0" => "sunday",
60
- "1" => "monday",
61
- "2" => "tuesday",
62
- "3" => "wednesday",
63
- "4" => "thursday",
64
- "5" => "friday",
65
- "6" => "saturday"
66
- }
60
+ # Maps values of [DateTime/Date/Time]#wday to English days
61
+ def days
62
+ {
63
+ "0" => "sunday",
64
+ "1" => "monday",
65
+ "2" => "tuesday",
66
+ "3" => "wednesday",
67
+ "4" => "thursday",
68
+ "5" => "friday",
69
+ "6" => "saturday"
70
+ }
71
+ end
67
72
  end
68
73
 
69
- end
74
+ # Extend so one can use InBusiness as a singleton module
75
+ extend InstanceMethods
76
+ end
@@ -1,3 +1,3 @@
1
1
  module InBusiness
2
- VERSION = '0.0.2'
3
- end
2
+ VERSION = '0.0.4'
3
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,5 +13,5 @@ RSpec.configure do |config|
13
13
  # order dependency and want to debug it, you can fix the order by providing
14
14
  # the seed, which is printed after each run.
15
15
  # --seed 1234
16
- config.order = 'random'
16
+ # config.order = 'random'
17
17
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'delegate'
3
+
4
+ class MyClass
5
+ include InBusiness
6
+ end
7
+
8
+ describe "Using InBusiness as a module" do
9
+ subject do
10
+ MyClass.new
11
+ end
12
+
13
+ describe "it responds to the same API as InBusiness" do
14
+ it { should respond_to(:open?) }
15
+ it { should respond_to(:closed?) }
16
+ it { should respond_to(:hours) }
17
+ it { should respond_to(:hours=) }
18
+ it { should respond_to(:holidays) }
19
+ it { should respond_to(:holidays=) }
20
+ it { should respond_to(:reset) }
21
+ it { should respond_to(:is_holiday?) }
22
+ it { should respond_to(:days) }
23
+ end
24
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in_business
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Tim Rogers
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-08 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,49 +27,43 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: timecop
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: activesupport
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  description: A gem for checking whether a given DateTime, Date or Time is within a
@@ -94,31 +85,32 @@ files:
94
85
  - lib/in_business/version.rb
95
86
  - spec/in_business_spec.rb
96
87
  - spec/spec_helper.rb
88
+ - spec/used_as_module_spec.rb
97
89
  homepage: https://github.com/timrogers/in_business
98
90
  licenses: []
91
+ metadata: {}
99
92
  post_install_message:
100
93
  rdoc_options: []
101
94
  require_paths:
102
95
  - lib
103
96
  required_ruby_version: !ruby/object:Gem::Requirement
104
- none: false
105
97
  requirements:
106
- - - ! '>='
98
+ - - '>='
107
99
  - !ruby/object:Gem::Version
108
100
  version: '0'
109
101
  required_rubygems_version: !ruby/object:Gem::Requirement
110
- none: false
111
102
  requirements:
112
- - - ! '>='
103
+ - - '>='
113
104
  - !ruby/object:Gem::Version
114
105
  version: '0'
115
106
  requirements: []
116
107
  rubyforge_project:
117
- rubygems_version: 1.8.23
108
+ rubygems_version: 2.0.3
118
109
  signing_key:
119
- specification_version: 3
110
+ specification_version: 4
120
111
  summary: A gem for checking whether a given DateTime, Date or Time is within a predefined
121
112
  set of opening hours
122
113
  test_files:
123
114
  - spec/in_business_spec.rb
124
115
  - spec/spec_helper.rb
116
+ - spec/used_as_module_spec.rb