in_business 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +2 -1
- data/lib/in_business.rb +57 -50
- data/lib/in_business/version.rb +2 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/used_as_module_spec.rb +24 -0
- metadata +15 -23
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?
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def self.holidays
|
10
|
-
@holidays
|
8
|
+
included do
|
9
|
+
include InstanceMethods
|
11
10
|
end
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
module InstanceMethods
|
13
|
+
def holidays
|
14
|
+
@holidays ||= []
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def holidays=(array)
|
18
|
+
@holidays = array
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
def hours
|
22
|
+
@hours ||= OpenStruct.new
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
49
|
+
true # It's not not open, so it must be open ;)
|
50
|
+
end
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
|
52
|
+
def closed?(datetime=DateTime.now)
|
53
|
+
!open?(datetime)
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
56
|
+
def is_holiday?(date=DateTime.now)
|
57
|
+
holidays.include? date.to_date
|
58
|
+
end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
74
|
+
# Extend so one can use InBusiness as a singleton module
|
75
|
+
extend InstanceMethods
|
76
|
+
end
|
data/lib/in_business/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module InBusiness
|
2
|
-
VERSION = '0.0.
|
3
|
-
end
|
2
|
+
VERSION = '0.0.4'
|
3
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -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.
|
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:
|
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:
|
108
|
+
rubygems_version: 2.0.3
|
118
109
|
signing_key:
|
119
|
-
specification_version:
|
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
|