bankholidays 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +5 -0
  2. data/README.md +18 -0
  3. data/lib/bankholidays.rb +38 -0
  4. metadata +156 -0
data/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ Copyright (c) 2012 James Inman <james@jamesinman.co.uk>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
+
5
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,18 @@
1
+ Simple gem to parse UK bank holidays from https://www.gov.uk/bank-holidays/.
2
+
3
+ #### Usage
4
+
5
+ Loop through all bank holidays:
6
+
7
+ BankHolidays.all.each do |h|
8
+ puts h[:date] # => 2012-12-25
9
+ puts h[:name] # => Christmas day
10
+ end
11
+
12
+ Find the next bank holiday:
13
+
14
+ BankHolidays.next
15
+
16
+ #### Dependencies
17
+
18
+ Requires the **httparty** and **icalendar** gems.
@@ -0,0 +1,38 @@
1
+ require 'httparty'
2
+ require 'uri'
3
+ require 'icalendar'
4
+ require 'date'
5
+
6
+ module BankHolidays
7
+
8
+ # Get a list of all bank holidays
9
+ def self.all
10
+ self.get_dates
11
+ end
12
+
13
+ # Get the next bank holiday
14
+ def self.next
15
+ self.get_dates.reject { |x| x[:date] < Date.today }.first
16
+ end
17
+
18
+ private
19
+
20
+ def self.get_dates
21
+ dates = []
22
+ year = Date.today.year
23
+ years = (year..(year + 10)).to_a
24
+
25
+ years.each do |y|
26
+ res = HTTParty.get "https://www.gov.uk/bank-holidays/england-and-wales-#{y}.ics"
27
+ break if res.code == 404
28
+ ics = Icalendar.parse( res )
29
+ cal = ics.first
30
+ cal.events.each do |e|
31
+ dates << { :date => e.dtstart, :name => e.summary }
32
+ end
33
+ end
34
+
35
+ dates
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bankholidays
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - James Inman
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: icalendar
31
+ type: :runtime
32
+ prerelease: false
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: httparty
45
+ type: :runtime
46
+ prerelease: false
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ name: shoulda
59
+ type: :development
60
+ prerelease: false
61
+ requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ hash: 31
69
+ segments:
70
+ - 3
71
+ - 12
72
+ version: "3.12"
73
+ name: rdoc
74
+ type: :development
75
+ prerelease: false
76
+ requirement: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ version_requirements: &id005 !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ hash: 23
84
+ segments:
85
+ - 1
86
+ - 0
87
+ - 0
88
+ version: 1.0.0
89
+ name: bundler
90
+ type: :development
91
+ prerelease: false
92
+ requirement: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ version_requirements: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ~>
98
+ - !ruby/object:Gem::Version
99
+ hash: 49
100
+ segments:
101
+ - 1
102
+ - 8
103
+ - 3
104
+ version: 1.8.3
105
+ name: jeweler
106
+ type: :development
107
+ prerelease: false
108
+ requirement: *id006
109
+ description: Library to parse UK bank holidays from https://www.gov.uk/bank-holidays/
110
+ email: james@jamesinman.co.uk
111
+ executables: []
112
+
113
+ extensions: []
114
+
115
+ extra_rdoc_files:
116
+ - LICENSE
117
+ - README.md
118
+ files:
119
+ - README.md
120
+ - lib/bankholidays.rb
121
+ - LICENSE
122
+ homepage: http://github.com/jfi/bankholidays
123
+ licenses:
124
+ - MIT
125
+ post_install_message:
126
+ rdoc_options: []
127
+
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ requirements: []
149
+
150
+ rubyforge_project:
151
+ rubygems_version: 1.8.17
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: Get UK bank holidays from www.gov.uk
155
+ test_files: []
156
+