when_easter 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/Gemfile +14 -0
  2. data/Gemfile.lock +40 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +20 -2
  5. data/Rakefile +50 -16
  6. data/VERSION +1 -1
  7. data/bin/find_distance +5 -0
  8. data/bin/when_easter +2 -2
  9. data/bin/when_greek_easter +2 -2
  10. data/bin/when_roman_easter +2 -2
  11. data/features/step_definitions/when_easter_steps.rb +68 -0
  12. data/features/support/env.rb +13 -0
  13. data/features/when_easter.feature +54 -0
  14. data/lib/when_easter.rb +64 -66
  15. data/spec/spec_helper.rb +12 -0
  16. data/spec/when_easter_spec.rb +9 -0
  17. data/when_easter.gemspec +30 -38
  18. metadata +97 -45
  19. data/doc/Rakefile.html +0 -110
  20. data/doc/VERSION.html +0 -88
  21. data/doc/WhenEaster.html +0 -380
  22. data/doc/bin/when_easter.html +0 -56
  23. data/doc/bin/when_greek_easter.html +0 -56
  24. data/doc/bin/when_roman_easter.html +0 -56
  25. data/doc/created.rid +0 -7
  26. data/doc/images/brick.png +0 -0
  27. data/doc/images/brick_link.png +0 -0
  28. data/doc/images/bug.png +0 -0
  29. data/doc/images/bullet_black.png +0 -0
  30. data/doc/images/bullet_toggle_minus.png +0 -0
  31. data/doc/images/bullet_toggle_plus.png +0 -0
  32. data/doc/images/date.png +0 -0
  33. data/doc/images/find.png +0 -0
  34. data/doc/images/loadingAnimation.gif +0 -0
  35. data/doc/images/macFFBgHack.png +0 -0
  36. data/doc/images/package.png +0 -0
  37. data/doc/images/page_green.png +0 -0
  38. data/doc/images/page_white_text.png +0 -0
  39. data/doc/images/page_white_width.png +0 -0
  40. data/doc/images/plugin.png +0 -0
  41. data/doc/images/ruby.png +0 -0
  42. data/doc/images/tag_green.png +0 -0
  43. data/doc/images/wrench.png +0 -0
  44. data/doc/images/wrench_orange.png +0 -0
  45. data/doc/images/zoom.png +0 -0
  46. data/doc/index.html +0 -68
  47. data/doc/js/darkfish.js +0 -116
  48. data/doc/js/jquery.js +0 -32
  49. data/doc/js/quicksearch.js +0 -114
  50. data/doc/js/thickbox-compressed.js +0 -10
  51. data/doc/lib/when_easter_rb.html +0 -52
  52. data/doc/rdoc.css +0 -759
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.6.0"
10
+ gem "cucumber", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.3"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.0.0)
5
+ cucumber (1.0.1)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (>= 1.1.2)
8
+ gherkin (~> 2.4.5)
9
+ json (>= 1.4.6)
10
+ term-ansicolor (>= 1.0.5)
11
+ diff-lcs (1.1.2)
12
+ gherkin (2.4.5)
13
+ json (>= 1.4.6)
14
+ git (1.2.5)
15
+ jeweler (1.6.4)
16
+ bundler (~> 1.0)
17
+ git (>= 1.2.5)
18
+ rake
19
+ json (1.5.3)
20
+ rake (0.9.2)
21
+ rcov (0.9.9)
22
+ rspec (2.6.0)
23
+ rspec-core (~> 2.6.0)
24
+ rspec-expectations (~> 2.6.0)
25
+ rspec-mocks (~> 2.6.0)
26
+ rspec-core (2.6.4)
27
+ rspec-expectations (2.6.0)
28
+ diff-lcs (~> 1.1.2)
29
+ rspec-mocks (2.6.0)
30
+ term-ansicolor (1.0.5)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.0.0)
37
+ cucumber
38
+ jeweler (~> 1.6.3)
39
+ rcov
40
+ rspec (~> 2.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Michał Nierebiński
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,18 +2,21 @@
2
2
 
3
3
  Ever wondered when will Easter (or Passover, if you prefer) be next year? No worries, use when_easter!
4
4
 
5
+ It's still being developed and refactored, so beware ;) Binaries work well though.
5
6
  ### Install
6
7
  $ gem install when_easter
7
8
 
8
9
  ### Use
9
10
 
10
11
  $ when_easter
11
- In the year 2010, the Roman Easter is on 24 April.
12
- In the year 2010, the Greek Easter is on 24 April.
12
+ In the year 2011, the Roman Easter is on 24 April.
13
+ In the year 2011, the Greek Easter is on 24 April.
14
+ In the year 2010 the distance between Roman and Greek Easter is 0 week(s).
13
15
 
14
16
  $ when_easter 2010
15
17
  In the year 2010, the Roman Easter is on 04 April.
16
18
  In the year 2010, the Greek Easter is on 04 April.
19
+ In the year 2010 the distance between Roman and Greek Easter is 0 week(s).
17
20
 
18
21
  If you want to find only one date, you can also try
19
22
 
@@ -21,7 +24,22 @@ If you want to find only one date, you can also try
21
24
  or
22
25
 
23
26
  $ when_greek_easter
27
+
28
+ and also
29
+
30
+ $ find_distance
31
+
32
+ If you wish, you can also use WhenEaster::EasterCalendar class and its methods to fetch the dates only
33
+
24
34
 
35
+ roman_date = WhenEaster::EasterCalendar.find_roman_easter_date(2010)
36
+ greek date is similiar - you can get it by replacing roman with greek
37
+
38
+ And get
39
+
40
+ => Sun Apr 21 00:00:00 +0200 2019
41
+ A Date object
42
+
25
43
  ### License
26
44
 
27
45
  Released under the MIT license.
data/Rakefile CHANGED
@@ -1,20 +1,54 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rubygems'
2
- require 'rake'
4
+ require 'bundler'
3
5
  begin
4
- require 'jeweler'
5
- Jeweler::Tasks.new do |gemspec|
6
- gemspec.name= "when_easter"
7
- gemspec.summary = "Get the date of Roman and Greek Easter"
8
- gemspec.description = "A tool that calculates the dates of Roman and Greek Easter."
9
- gemspec.email = "michal@nierebinski.pl"
10
- gemspec.homepage = "https://github.com/Loyolny/when_easter"
11
- gemspec.executables = ["when_easter","when_roman_easter","when_greek_easter"]
12
- gemspec.authors = ["Michał Nierebiński"]
13
- gemspec.date = File.utime(0,0,'VERSION')
14
-
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Ya don't have Jeweler gem installed. Install it with: sudo gem install jeweler"
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "when_easter"
18
+ gem.homepage = "http://github.com/Loyolny/when_easter"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Get the date of Roman and Greek Easter}
21
+ gem.description = %Q{A tool that calculates the dates of Roman and Greek Easter.}
22
+ gem.email = "michal@nierebinski.pl"
23
+ gem.authors = ["Michał Nierebiński"]
24
+ gem.date = File.utime(0,0,'VERSION')
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ require 'cucumber/rake/task'
41
+ Cucumber::Rake::Task.new(:features)
42
+
43
+ task :default => :spec
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "when_easter #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
53
  end
20
54
  #Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.3.0
data/bin/find_distance ADDED
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+ require "rubygems"
3
+ require "when_easter"
4
+ calendar = WhenEaster::EasterCalendar.new(ARGV[0])
5
+ puts calendar.find_distance
data/bin/when_easter CHANGED
@@ -1,5 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
2
  require "rubygems"
3
3
  require "when_easter"
4
-
5
- puts WhenEaster.find(ARGV[0])
4
+ calendar = WhenEaster::EasterCalendar.new(ARGV[0])
5
+ puts calendar.find
@@ -1,5 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
2
  require "rubygems"
3
3
  require "when_easter"
4
-
5
- puts WhenEaster.find_greek(ARGV[0])
4
+ calendar = WhenEaster::EasterCalendar.new(ARGV[0])
5
+ puts calendar.find_greek
@@ -1,5 +1,5 @@
1
1
  #! /usr/bin/env ruby
2
2
  require "rubygems"
3
3
  require "when_easter"
4
-
5
- puts WhenEaster.find_roman(ARGV[0])
4
+ calendar = WhenEaster::EasterCalendar.new(ARGV[0])
5
+ puts calendar.find_roman
@@ -0,0 +1,68 @@
1
+ Given /^an easter_calendar with no date specified$/ do
2
+ @easter_calendar = WhenEaster::EasterCalendar.new
3
+ end
4
+
5
+ Given /^year (\d+)$/ do |year|
6
+ @given_year = year
7
+ end
8
+
9
+ Given /^an easter_calendar$/ do
10
+ @easter_calendar = WhenEaster::EasterCalendar.new(@given_year)
11
+ end
12
+ When /^I ask for the year$/ do
13
+ @year = @easter_calendar.year
14
+ end
15
+ When /^I find roman easter$/ do
16
+ @roman_date = @easter_calendar.class.find_roman_easter_date(@easter_calendar.year)
17
+ end
18
+ When /^I find greek easter$/ do
19
+ @greek_date = @easter_calendar.class.find_greek_easter_date(@easter_calendar.year)
20
+ end
21
+ Then /^I should see year (\d+) in an easter_calendar$/ do |year|
22
+ @year.should == year.to_i
23
+ end
24
+
25
+ Then /^I should see "([^"]*)" in the output$/ do |date|
26
+ @date.to_s.should == date
27
+ end
28
+
29
+ When /^I ask for roman easter date$/ do
30
+ @roman_date = @easter_calendar.find_roman
31
+ end
32
+
33
+ When /^I ask for greek easter date$/ do
34
+ @greek_date = @easter_calendar.find_greek
35
+ end
36
+
37
+ Then /^I should see "([^"]*)"$/ do |easter_date|
38
+ @date.should == easter_date
39
+ end
40
+ Then /^I should see roman easter date "([^"]*)" in the output$/ do |date|
41
+ @roman_date.to_s.should == date
42
+ end
43
+
44
+ Then /^I should see greek easter date "([^"]*)" in the output$/ do |date|
45
+ @greek_date.to_s.should == date
46
+ end
47
+
48
+ When /^I ask for distance between easters$/ do
49
+ @distance = @easter_calendar.find_distance
50
+ end
51
+
52
+ Then /^I should see a distance in weeks as "([^"]*)"$/ do |distance|
53
+ @distance.should == distance
54
+ end
55
+ Then /^I should see correct Roman date: "([^"]*)"$/ do |date|
56
+ @roman_date.to_s.should == date
57
+ end
58
+
59
+ Then /^I should see correct Greek date: "([^"]*)"$/ do |date|
60
+ @greek_date.to_s.should == date
61
+ end
62
+
63
+ When /^I ask for complete easter information$/ do
64
+ @roman_date = @easter_calendar.find_roman
65
+ @greek_date = @easter_calendar.find_greek
66
+ @distance = @easter_calendar.find_distance
67
+ end
68
+
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
11
+ require 'when_easter'
12
+
13
+ require 'rspec/expectations'
@@ -0,0 +1,54 @@
1
+ Feature: EasterCalendar returns date
2
+
3
+ In order to find liturgical date
4
+ As a common churchgoer
5
+ I want an easter_calendar to find easter date
6
+
7
+ Scenario: easter_calendar sets default year
8
+ Given an easter_calendar with no date specified
9
+ When I ask for the year
10
+ Then I should see year 2011 in an easter_calendar
11
+
12
+ Scenario: easter_calendar sets given year
13
+ Given year 2016
14
+ And an easter_calendar
15
+ When I ask for the year
16
+ Then I should see year 2016 in an easter_calendar
17
+
18
+ Scenario: easter_calendar finds roman easter date
19
+ Given year 2016
20
+ And an easter_calendar
21
+ When I find roman easter
22
+ Then I should see roman easter date "Sun Mar 27 00:00:00 +0100 2016" in the output
23
+
24
+ Scenario: easter_calendar finds greek easter date
25
+ Given year 2017
26
+ And an easter_calendar
27
+ When I find greek easter
28
+ Then I should see greek easter date "Sun Apr 16 00:00:00 +0200 2017" in the output
29
+
30
+ Scenario: easter_calendar prints out the roman easter date
31
+ Given year 2016
32
+ And an easter_calendar
33
+ When I ask for roman easter date
34
+ Then I should see correct Roman date: "In the year 2016 the Roman Easter is on 27 March."
35
+
36
+ Scenario: easter_calendar prints out the greek easter date
37
+ Given year 2017
38
+ And an easter_calendar
39
+ When I ask for greek easter date
40
+ Then I should see correct Greek date: "In the year 2017 the Greek Easter is on 16 April."
41
+
42
+ Scenario: easter_calendar prints out the distance between greek and roman easter
43
+ Given year 2020
44
+ And an easter_calendar
45
+ When I ask for distance between easters
46
+ Then I should see a distance in weeks as "In the year 2020 the distance between Roman and Greek Easter is 1 week(s)."
47
+
48
+ Scenario: easter_calendar prints out full information about easter dates
49
+ Given year 2019
50
+ And an easter_calendar
51
+ When I ask for complete easter information
52
+ Then I should see correct Roman date: "In the year 2019 the Roman Easter is on 21 April."
53
+ And I should see correct Greek date: "In the year 2019 the Greek Easter is on 28 April."
54
+ And I should see a distance in weeks as "In the year 2019 the distance between Roman and Greek Easter is 1 week(s)."
data/lib/when_easter.rb CHANGED
@@ -1,72 +1,70 @@
1
- class WhenEaster
2
- # WhenEaster.find
3
- #=> In the year 2011, the Roman Easter is on 24 April. \n In the year 2011, the Greek Easter is on 24 April.
4
- def self.find(year = nil)
5
- roman_date = self.roman_easter(year)
6
- greek_date = self.greek_easter(year)
7
- return "In the year #{roman_date.year}, the Roman Easter is on #{roman_date.strftime("%d %B")}. \nIn the year #{greek_date.year}, the Greek Easter is on #{greek_date.strftime("%d %B")}."
8
- end
9
-
10
- # WhenEaster.find_roman
11
- #=> In the year 2011, the Roman Easter is on 24 April.
12
- def self.find_roman(year = nil)
13
- date = self.roman_easter(year)
14
- return "In the year #{date.year}, the Roman Easter is on #{date.strftime("%d %B")}."
15
- end
16
-
17
- ## WhenEaster.find_greek
18
- ##=> In the year 2011, the Greek Easter is on 24 April.
19
- def self.find_greek(year)
20
- date = self.greek_easter(year)
21
- return "In the year #{date.year}, the Greek Easter is on #{date.strftime("%d %B")}."
22
- end
23
- # WhenEaster.roman_easter
24
- # => Sun Apr 24 00:00:00 +0200 2011
25
- def self.roman_easter(year = nil)
26
- year = Time.now.year if year.nil?
27
- year = year.to_i if year.is_a?(String)
28
- g = year % 19 +1
29
- s = (year -1600) / 100 - (year-1600) / 400
30
- l = (((year - 1400) / 100) * 8) / 25
31
-
32
- p_2 = (3-11*g +s -l) % 30
33
- if p_2 == 29 || (p_2 == 28 && g > 11)
34
- p = p_2 -1
35
- else
36
- p= p_2
1
+ module WhenEaster
2
+ class EasterCalendar
3
+
4
+ attr_reader :year
5
+ def initialize(year = nil)
6
+ @year = Time.now.year if year.nil?
7
+ @year = year if year.is_a?(Integer)
8
+ @year = year.to_i if year.is_a?(String)
9
+ end
10
+ def distance_in_weeks
11
+ ((self.class.find_greek_easter_date(year) - self.class.find_roman_easter_date(year))/3600/24/7).to_i
12
+ end
13
+ def find
14
+ find_roman+"\n"+find_greek+"\n"+find_distance
37
15
  end
38
16
 
39
- d= (year + year / 4 - year / 100 + year / 400) % 7
40
- d_2 = (8-d) % 7
41
-
42
- p_3 = (80 + p) % 7
43
- x_2 = d_2 - p_3
44
-
45
- x = (x_2 -1) % 7 +1
46
- e = p+x
47
-
48
- if e < 11
49
- Time.local(year,3,e+21)
50
- else
51
- Time.local(year,4,e-10)
17
+ def find_roman
18
+ "In the year #{@year} the Roman Easter is on #{self.class.find_roman_easter_date(@year).strftime("%d %B")}."
52
19
  end
53
- end
54
-
55
- # WhenEaster.greek_easter
56
- # => Sun Apr 24 00:00:00 +0200 2011
57
- def self.greek_easter(year = nil)
58
- year = Time.now.year if year.nil?
59
- year = year.to_i if year.is_a?(String)
60
- a = year % 19
61
- b = year % 4
62
- c = year % 7
63
- d = (19 * a + 16) % 30
64
- e = (2 * b + 4 * c + 6 * d) % 7;
65
- easter = 3 + d + e;
66
- if easter <= 30
67
- Time.local(year, 4, easter)
68
- else
69
- Time.local(year, 5, (easter - 30))
20
+ def find_greek
21
+ "In the year #{@year} the Greek Easter is on #{self.class.find_greek_easter_date(@year).strftime("%d %B")}."
22
+ end
23
+ def find_distance
24
+ "In the year #{@year} the distance between Roman and Greek Easter is #{distance_in_weeks} week(s)."
25
+ end
26
+ # => Sun Apr 24 00:00:00 +0200 2011
27
+ def self.find_roman_easter_date(year)
28
+ g = year % 19 +1
29
+ s = (year -1600) / 100 - (year-1600) / 400
30
+ l = (((year - 1400) / 100) * 8) / 25
31
+
32
+ p_2 = (3-11*g +s -l) % 30
33
+ if p_2 == 29 || (p_2 == 28 && g > 11)
34
+ p = p_2 -1
35
+ else
36
+ p= p_2
37
+ end
38
+
39
+ d= (year + year / 4 - year / 100 + year / 400) % 7
40
+ d_2 = (8-d) % 7
41
+
42
+ p_3 = (80 + p) % 7
43
+ x_2 = d_2 - p_3
44
+
45
+ x = (x_2 -1) % 7 +1
46
+ e = p+x
47
+
48
+ if e < 11
49
+ Time.local(year,3,e+21)
50
+ else
51
+ Time.local(year,4,e-10)
52
+ end
53
+ end
54
+
55
+ # => Sun Apr 24 00:00:00 +0200 2011
56
+ def self.find_greek_easter_date(year)
57
+ a = year % 19
58
+ b = year % 4
59
+ c = year % 7
60
+ d = (19 * a + 16) % 30
61
+ e = (2 * b + 4 * c + 6 * d) % 7;
62
+ easter = 3 + d + e;
63
+ if easter <= 30
64
+ Time.local(year, 4, easter)
65
+ else
66
+ Time.local(year, 5, (easter - 30))
67
+ end
70
68
  end
71
69
  end
72
70
  end