bbc-week 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a2f6ef9801940e51834ce4527ff27a60803d4e144a9eb09d867dc445a595f81e
4
+ data.tar.gz: 2df8a40832baab4aedd321eac5b63d5a367e173a16123131d50418a7759511f9
5
+ SHA512:
6
+ metadata.gz: 0e30336801ebd2321686ed093faa60b3dd244095fcdfb7e756009e7bfda56b39637bfbdb9db22457f6ae4ca8960ef387d8bed4428f2c35680162ac303a6f7b4e
7
+ data.tar.gz: 98f4788182ab5be4e114fb31bc5a491fe2458cb6f6b4dbe9fa0b1d20b251978d4f49e1611686bb0914aafe4edf2c8c470d8cda4c3cc2baec5aa7f899b4d2f499
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.5
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bbc-week.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 British Broadcasting Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,82 @@
1
+ # BBC::Week Ruby Gem
2
+
3
+ Some BBC production teams plan their programming around week numbers, counting from the start of the year. Unfortunately this is different to the definition of an [ISO Week] or commercial week. The BBC publishes a programme week wall calendar to production staff, so that they can quickly identify the week number.
4
+
5
+ The rules for calculating the BBC week number are:
6
+ - Weeks start with Saturday
7
+ - Each week's year is the Gregorian year in which the Tuesday falls
8
+ - The first week of the year always contains 4th January
9
+
10
+
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'bbc-week'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle install
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install bbc-week
27
+
28
+ ## Usage
29
+
30
+ After requiring `bbc-week`, two methods are added to the ruby [Date] class.
31
+
32
+ Days are numbered from Saturday:
33
+
34
+ | Number | Day |
35
+ |---------|-----------|
36
+ | 1 | Saturday |
37
+ | 2 | Sunday |
38
+ | 3 | Monday |
39
+ | 4 | Tuesday |
40
+ | 5 | Wednesday |
41
+ | 6 | Thursday |
42
+ | 7 | Friday |
43
+
44
+
45
+ ### Date.bbc_week(year, week, day)
46
+
47
+ This class method creates a new [Date] object, based on a BBC year, week and day.
48
+
49
+ ### Date#bbc_week
50
+
51
+ This instance method returns the BBC year, week and day as an array.
52
+
53
+
54
+ ### Example Console Session
55
+
56
+ ```ruby
57
+ $ ./bin/console
58
+ irb(main):001:0> Date.today.bbc_week
59
+ => [2020, 33, 6]
60
+ irb(main):002:0> Date.bbc_week(2020, 33, 6)
61
+ => #<Date: 2020-08-20 ((2459082j,0s,0n),+0s,2299161j)>
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bbc/ruby-bbc-week.
73
+
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
78
+
79
+
80
+
81
+ [ISO Week]: https://en.wikipedia.org/wiki/ISO_week_date
82
+ [Date]: https://ruby-doc.org/stdlib/libdoc/date/rdoc/Date.html
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ require_relative 'lib/bbc/week/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "bbc-week"
5
+ spec.version = BBC::Week::VERSION
6
+ spec.authors = ["British Broadcasting Corporation"]
7
+
8
+ spec.summary = %q{Extension to the Date class to calculate BBC week dates}
9
+ spec.homepage = "https://github.com/bbc/ruby-bbc-week"
10
+ spec.license = "MIT"
11
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+
13
+ spec.metadata["homepage_uri"] = spec.homepage
14
+ spec.metadata["source_code_uri"] = "https://github.com/bbc/ruby-bbc-week.git"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bbc/week"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ require "bbc/week/version"
2
+ require 'date'
3
+
4
+ module BBC
5
+ module Week
6
+ def self.included(klass)
7
+ klass.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ # Create a date object from a BBC week date
12
+ def bbc_week(year, week, day)
13
+ # The week that contains Jan 4 is the first week with the majority
14
+ # of days in that year (regardless of what day of week is start of week)
15
+ jan4 = Date.new(year, 1, 4)
16
+
17
+ # Next calculate the first day of the first week of that year
18
+ first = jan4 - ((jan4.wday + 1) % 7)
19
+
20
+ # Then add on the days and weeks
21
+ first + ((week - 1) * 7) + day - 1
22
+ end
23
+ end
24
+
25
+ # Convert a Date object to BBC Week
26
+ def bbc_week
27
+ adjustment = 3 - ((self.wday + 1) % 7)
28
+ tuesday = self + adjustment
29
+ [tuesday.year, ((tuesday.yday - 1) / 7) + 1, 4 - adjustment]
30
+ end
31
+ end
32
+ end
33
+
34
+ class Date
35
+ include BBC::Week
36
+ end
@@ -0,0 +1,5 @@
1
+ module BBC
2
+ module Week
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bbc-week
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - British Broadcasting Corporation
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".gitignore"
20
+ - ".travis.yml"
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - bbc-week.gemspec
26
+ - bin/console
27
+ - bin/setup
28
+ - lib/bbc/week.rb
29
+ - lib/bbc/week/version.rb
30
+ homepage: https://github.com/bbc/ruby-bbc-week
31
+ licenses:
32
+ - MIT
33
+ metadata:
34
+ homepage_uri: https://github.com/bbc/ruby-bbc-week
35
+ source_code_uri: https://github.com/bbc/ruby-bbc-week.git
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.3.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.1.4
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Extension to the Date class to calculate BBC week dates
55
+ test_files: []