bank_holiday 0.0.2 → 0.0.3

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: 14ac3023c2436c0fe22f8bf457a15141239f8897
4
- data.tar.gz: bc44a421a9e7fb3d856cc80543a64d6e68f1d177
3
+ metadata.gz: f245723987a458fd500cd99489e01b095aaf3feb
4
+ data.tar.gz: c561996d16660e1b8a66e618762f0ad50fe8d4a2
5
5
  SHA512:
6
- metadata.gz: bc6114cdcbf20e347e606aafd9d8b98eada00db39e5693f6a8e9bb7ca88a306bc518d4e33ab06e9fa23b5efc213d3e1cfec0b702f1bda9dc76af384d4ccb7858
7
- data.tar.gz: e08e42a645b763213aa7b0fbf209780f24d07a0e5a76f46e0c6b35c3e89c0707394a55a78c1532a6f477370d9fd757db8ab3ea629b653a3ff6d83882ba4606ef
6
+ metadata.gz: 12726d60eb0112188afb6607e26d1956fddf4fa1ebece7a83159e6743edc2a529092f7a337b84ec6728a82501656b4d914dd103158dcce63b3519a159de7034d
7
+ data.tar.gz: a1834b836cb5f6b034cbf29fa1d95a0130cb826d34f93b424a38836dbb65adfb516edd847507788ad33d054de02dad4b0ffc9579989c949f3b71f54404603030
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # Bank Holiday
2
+
3
+ Retrieve UK bank holidays in a nice format and includes handy Rails helpers for dates.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem "bank_holiday"
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bank_holiday
18
+
19
+ ## Usage
20
+
21
+ ### Helpers
22
+
23
+ If you want to see if a date is a bank holiday then simply use;
24
+
25
+ date = Date.today
26
+ => Thu, 17 Jul 2014
27
+
28
+ date.bank_holiday?
29
+ => false
30
+
31
+ date = Date.parse("25/08/2014")
32
+ => Mon, 25 Aug 2014
33
+
34
+ date.bank_holiday?
35
+ => true
36
+
37
+ ### Accessing Holidays
38
+
39
+ To return all bank holidays
40
+
41
+ bank_holidays = BankHoliday.all
42
+
43
+ This uses the Dish gem to allow easy access to the objects;
44
+
45
+ bank_holidays.first.title
46
+ => "New Year’s Day"
47
+
48
+ bank_holiday.first.date
49
+ => "2012-01-02"
50
+
51
+ bank_holiday.first.notes
52
+ => "Substitute day"
53
+
54
+ bank_holiday.first.bunting
55
+ => true
56
+
57
+ There is also some other helpful methods;
58
+
59
+ after_date = BankHoliday.after(Date.today)
60
+ => [#<Dish::Plate:0x007f831e886c80 @_original_hash={"title"=>"Summer bank holiday", "date"=>"2014-08-25", "notes"=>"", "bunting"=>true}>, #<Dish::Plate:0x007f831e886aa0 @_original_hash={"title"=>"Christmas Day", "date"=>"2014-12-25", "notes"=>"", "bunting"=>true}>, #<Dish::Plate:0x007f831e8868c0 @_original_hash={"title"=>"Boxing Day", "date"=>"2014-12-26", "notes"=>"", "bunting"=>true}>...]
61
+
62
+ before_date = BankHoliday.before(1.month.ago)
63
+ => [#<Dish::Plate:0x007f831e855630 @_original_hash={"title"=>"New Year’s Day", "date"=>"2012-01-02", "notes"=>"Substitute day", "bunting"=>true}>, #<Dish::Plate:0x007f831e855450 @_original_hash={"title"=>"Good Friday", "date"=>"2012-04-06", "notes"=>"", "bunting"=>false}>, #<Dish::Plate:0x007f831e855270 @_original_hash={"title"=>"Easter Monday", "date"=>"2012-04-09", "notes"=>"", "bunting"=>true}>...]
64
+
65
+ next = BankHoliday.next
66
+ => #<Dish::Plate:0x007f831e886c80 @_original_hash={"title"=>"Summer bank holiday", "date"=>"2014-08-25", "notes"=>"", "bunting"=>true}>
67
+
68
+ last = BankHoliday.last
69
+ => #<Dish::Plate:0x007f831e886e60 @_original_hash={"title"=>"Spring bank holiday", "date"=>"2014-05-26", "notes"=>"", "bunting"=>true}>
70
+
71
+ future = BankHoliday.future
72
+ => [#<Dish::Plate:0x007f831e886c80 @_original_hash={"title"=>"Summer bank holiday", "date"=>"2014-08-25", "notes"=>"", "bunting"=>true}>, #<Dish::Plate:0x007f831e886aa0 @_original_hash={"title"=>"Christmas Day", "date"=>"2014-12-25", "notes"=>"", "bunting"=>true}>, #<Dish::Plate:0x007f831e8868c0 @_original_hash={"title"=>"Boxing Day", "date"=>"2014-12-26", "notes"=>"", "bunting"=>true}>...]
73
+
74
+ past = BankHoliday.past
75
+ => [#<Dish::Plate:0x007f831e855630 @_original_hash={"title"=>"New Year’s Day", "date"=>"2012-01-02", "notes"=>"Substitute day", "bunting"=>true}>, #<Dish::Plate:0x007f831e855450 @_original_hash={"title"=>"Good Friday", "date"=>"2012-04-06", "notes"=>"", "bunting"=>false}>, #<Dish::Plate:0x007f831e855270 @_original_hash={"title"=>"Easter Monday", "date"=>"2012-04-09", "notes"=>"", "bunting"=>true}>...]
76
+
77
+ ## Future
78
+
79
+ I would like to add other options/features to this and would welcome any improvements or changes.
80
+
81
+ ## Contributing
82
+
83
+ 1. Fork it
84
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
85
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
86
+ 4. Push to the branch (`git push origin my-new-feature`)
87
+ 5. Create new Pull Request
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'bank_holiday/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'bank_holiday'
7
+ s.version = BankHoliday::VERSION
8
+ s.date = '2014-07-25'
9
+ s.summary = "Finding bank holidays including helpers for dates."
10
+ s.description = "Finding bank holidays including helpers for dates."
11
+ s.authors = ["Craig Sheen"]
12
+ s.email = 'craig_sheen@hotmail.com'
13
+ s.files = ["lib/bank_holiday.rb"]
14
+ s.homepage = 'https://github.com/craigsheen/bank_holiday'
15
+ s.license = 'MIT'
16
+
17
+ s.add_dependency 'dish'
18
+ s.require_paths = ["lib", "lib/bank_holiday"]
19
+ s.files = `git ls-files`.split($/)
20
+ end
@@ -0,0 +1,54 @@
1
+ require 'dish/ext'
2
+
3
+ module BankHoliday
4
+
5
+ URL = "https://www.gov.uk/bank-holidays.json"
6
+
7
+ def self.all
8
+ uri = URI.parse(URL)
9
+ http = Net::HTTP.new(uri.host, uri.port)
10
+ http.use_ssl = true
11
+ request = Net::HTTP::Get.new(uri.request_uri)
12
+ response = http.request(request)
13
+ bank_holidays = response.body
14
+ return Dish(JSON.parse(bank_holidays)["england-and-wales"]["events"])
15
+ end
16
+
17
+ def self.after(date)
18
+ @bank_holidays||=all
19
+ @bank_holidays.reject{ |h| Date.parse(h.date) <= date }
20
+ end
21
+
22
+ def self.before(date)
23
+ @bank_holidays||=all
24
+ @bank_holidays.reject{ |h| Date.parse(h.date) >= date }
25
+ end
26
+
27
+ def self.next
28
+ future.first
29
+ end
30
+
31
+ def self.last
32
+ past.last
33
+ end
34
+
35
+ def self.future
36
+ @bank_holidays||=all
37
+ @bank_holidays.reject{ |h| Date.parse(h.date) <= Date.today }
38
+ end
39
+
40
+ def self.past
41
+ @bank_holidays||=all
42
+ @bank_holidays.reject{ |h| Date.parse(h.date) >= Date.today }
43
+ end
44
+
45
+ def self.bank_holiday?(date)
46
+ @bank_holidays||=all
47
+ if @bank_holidays.collect {|holiday| holiday.date}.include?(date.strftime("%Y-%m-%d"))
48
+ return true
49
+ else
50
+ return false
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,8 @@
1
+ require 'bank_holiday'
2
+ class Date
3
+
4
+ def bank_holiday?
5
+ BankHoliday.bank_holiday?(self)
6
+ end
7
+
8
+ end
@@ -0,0 +1,3 @@
1
+ module BankHoliday
2
+ VERSION = "0.0.3"
3
+ end
data/lib/bank_holiday.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require 'net/http'
2
- require "dish/ext"
2
+ require 'dish/ext'
3
3
  require 'bank_holiday/date'
4
- require 'bank_holiday/bank_holiday'
4
+ require 'bank_holiday/bank_holiday'
5
+
6
+ module BankHoliday
7
+
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank_holiday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Sheen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dish
@@ -30,8 +30,14 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
+ - Gemfile
34
+ - README.md
35
+ - bank_holiday.gemspec
33
36
  - lib/bank_holiday.rb
34
- homepage: ''
37
+ - lib/bank_holiday/bank_holiday.rb
38
+ - lib/bank_holiday/date.rb
39
+ - lib/bank_holiday/version.rb
40
+ homepage: https://github.com/craigsheen/bank_holiday
35
41
  licenses:
36
42
  - MIT
37
43
  metadata: {}
@@ -39,6 +45,7 @@ post_install_message:
39
45
  rdoc_options: []
40
46
  require_paths:
41
47
  - lib
48
+ - lib/bank_holiday
42
49
  required_ruby_version: !ruby/object:Gem::Requirement
43
50
  requirements:
44
51
  - - '>='