shire 0.0.1 → 0.1.0

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.
data/CHANGELOG CHANGED
@@ -0,0 +1,9 @@
1
+ = Shire Changelog
2
+
3
+ == Version 0.1.0
4
+
5
+ * Added the shire command.
6
+
7
+ == Version 0.0.1
8
+
9
+ * Added extensions for the Time and Date classes.
data/README CHANGED
@@ -4,6 +4,13 @@ Shire extends the Time and Date classes for hobbits.
4
4
 
5
5
  Shire is based on Tom Braun's DateTime::Fiction::JRRTolkien::Shire[http://search.cpan.org/~tbraun/DateTime-Fiction-JRRTolkien-Shire-0.02/] Perl module and is implemented in Ruby in the style of the ActiveSupport[http://rubyforge.org/projects/activesupport] core extensions.
6
6
 
7
+ The methods that hobbits will find useful are listed in Shire::CoreExtensions::Time::Calculations.
8
+
9
+ The <code>shire</code> command prints today's date:
10
+
11
+ % shire
12
+ Sunday 26 Foreyule 7470
13
+
7
14
 
8
15
  == Download
9
16
 
@@ -22,7 +29,7 @@ The preferred method of installing Shire is through its GEM file. You'll need to
22
29
  RubyGems[http://rubygems.rubyforge.org/wiki/wiki.pl] installed for that, though. If you have it,
23
30
  then use:
24
31
 
25
- % [sudo] gem install shire-0.0.1.gem
32
+ % [sudo] gem install shire-0.1.0.gem
26
33
 
27
34
 
28
35
  == Time Example
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'shire'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'shire'
6
+ end
7
+ puts Time.now.shire_on_date
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/time/calculations'
2
2
  require File.dirname(__FILE__) + '/time/constants'
3
3
 
4
- class Date
4
+ class Date #:nodoc:
5
5
  include Shire::CoreExtensions::Time::Constants
6
6
  include Shire::CoreExtensions::Time::Calculations
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/time/calculations'
2
2
  require File.dirname(__FILE__) + '/time/constants'
3
3
 
4
- class Time
4
+ class Time #:nodoc:
5
5
  include Shire::CoreExtensions::Time::Constants
6
6
  include Shire::CoreExtensions::Time::Calculations
7
7
  end
@@ -1,87 +1,93 @@
1
- module Shire
2
- module CoreExtensions
3
- module Time
4
- module Calculations
1
+ module Shire #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Time #:nodoc:
4
+ # Date calculations for hobbits.
5
+ module Calculations
6
+ def self.method_added(method) #:nodoc:
7
+ return unless method.to_s =~ /^shire/
8
+ wrap_shire_method(method)
9
+ end
10
+
11
+ def self.wrap_shire_method(method) #:nodoc:
12
+ wrapped_method = "wrapped_#{method}"
13
+ return if instance_methods.include? wrapped_method
14
+ alias_method wrapped_method, method
15
+ module_eval %{
16
+ def #{method}(*args)
17
+ calculate_shire
18
+ #{wrapped_method}(*args)
19
+ end
20
+ }
21
+ private wrapped_method
22
+ end
23
+
5
24
  # Returns the year.
6
25
  def shire_year
7
- calculate_shire
8
26
  @shire_year
9
27
  end
10
28
 
11
29
  # Returns the day of the year.
12
30
  def shire_yday
13
- calculate_shire
14
31
  @shire_yday
15
32
  end
16
33
 
17
34
  # Returns whether the year is a leap year.
18
35
  def shire_leap_year?
19
- calculate_shire
20
- @shire_leap_year
36
+ @shire_leap_year
21
37
  end
22
38
 
23
- # Returns the holiday day number or nil if the date is not a holiday.
39
+ # Returns the holiday number or nil if the date is not a holiday.
24
40
  def shire_holiday
25
- calculate_shire
26
41
  @shire_holiday
27
42
  end
28
43
 
29
44
  # Returns whether the date is a holiday.
30
45
  def shire_holiday?
31
- calculate_shire
32
46
  @shire_holiday != nil
33
47
  end
34
48
 
35
49
  # Returns the name of the holiday or nil if the date is not a holiday.
36
50
  def shire_holiday_name
37
- calculate_shire
38
51
  Constants::SHIRE_HOLIDAY_NAMES[shire_holiday] if shire_holiday?
39
52
  end
40
53
 
41
54
  # Returns the number of the day of the week or nil if not a day of the week.
42
55
  def shire_wday
43
- calculate_shire
44
56
  @shire_wday
45
57
  end
46
58
 
47
59
  # Returns whether the date is a day of the week.
48
60
  def shire_wday?
49
- calculate_shire
50
61
  @shire_wday != nil
51
62
  end
52
63
 
53
64
  # Returns the month number.
54
65
  def shire_month
55
- calculate_shire
56
66
  @shire_month
57
67
  end
58
68
 
59
69
  # Returns the day of the month.
60
70
  def shire_day
61
- calculate_shire
62
71
  @shire_day
63
72
  end
64
73
 
65
74
  # Returns the name of the day of the week or nil if not a day of the week.
66
75
  def shire_day_name
67
- calculate_shire
68
76
  Constants::SHIRE_DAY_NAMES[shire_wday] if shire_wday
69
77
  end
70
78
 
71
79
  # Returns the traditional name of the day of the week or nil if not a day of the week.
72
80
  def shire_traditional_day_name
73
- calculate_shire
74
81
  Constants::SHIRE_TRADITIONAL_DAY_NAMES[shire_wday] if shire_wday
75
82
  end
76
83
 
77
84
  # Returns the name of the month or nil if not a day of a month.
78
85
  def shire_month_name
79
- calculate_shire
80
86
  Constants::SHIRE_MONTH_NAMES[shire_month]
81
87
  end
82
88
 
89
+ # Returns any events that occurred on this date.
83
90
  def shire_events
84
- calculate_shire
85
91
  if shire_holiday?
86
92
  Constants::SHIRE_EVENTS[0][shire_holiday]
87
93
  else
@@ -89,14 +95,13 @@ module Shire
89
95
  end
90
96
  end
91
97
 
98
+ # Returns whether any events occurred on this date.
92
99
  def shire_events?
93
- calculate_shire
94
100
  shire_events != nil
95
101
  end
96
102
 
97
103
  # Returns the date and any events that occurred on that date.
98
104
  def shire_on_date
99
- calculate_shire
100
105
  if shire_events?
101
106
  "#{shire_to_s}\n\n#{shire_events}"
102
107
  else
@@ -106,7 +111,6 @@ module Shire
106
111
 
107
112
  # Returns the date.
108
113
  def shire_to_s
109
- calculate_shire
110
114
  if shire_holiday?
111
115
  if shire_wday?
112
116
  "#{shire_day_name} #{shire_holiday_name} #{shire_year}"
@@ -1,12 +1,12 @@
1
- module Shire
2
- module CoreExtensions
3
- module Time
1
+ module Shire #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Time #:nodoc:
4
+ # Date constants for hobbits.
4
5
  module Constants
5
- SHIRE_DAY_NAMES = ['Sterday', 'Sunday', 'Monday', 'Trewsday', 'Hevensday', 'Mersday', 'Highday']
6
- SHIRE_TRADITIONAL_DAY_NAMES = ['Sterrendei', 'Sunnendei', 'Monendei', 'Trewesdei', 'Hevenesdei', 'Meresdei', 'Highdei']
7
- SHIRE_MONTH_NAMES = [nil, 'Afteryule', 'Solmath', 'Rethe', 'Astron',
8
- 'Thrimidge', 'Forelithe', 'Afterlithe', 'Wedmath', 'Halimath', 'Winterfilth', 'Blotmath', 'Foreyule']
9
- SHIRE_HOLIDAY_NAMES = [nil, '2 Yule', '1 Lithe', "Midyear's day", 'Overlithe', '2 Lithe', '1 Yule']
6
+ SHIRE_DAY_NAMES = %w(Sterday Sunday Monday Trewsday Hevensday Mersday Highday)
7
+ SHIRE_TRADITIONAL_DAY_NAMES = %w(Sterrendei Sunnendei Monendei Trewesdei Hevenesdei Meresdei Highdei)
8
+ SHIRE_MONTH_NAMES = [nil] + %w(Afteryule Solmath Rethe Astron Thrimidge Forelithe Afterlithe Wedmath Halimath Winterfilth Blotmath Foreyule)
9
+ SHIRE_HOLIDAY_NAMES = [nil] + ['2 Yule', '1 Lithe', "Midyear's day", 'Overlithe', '2 Lithe', '1 Yule']
10
10
  SHIRE_EVENTS = {
11
11
  0 => {
12
12
  3 => "Wedding of King Elessar and Arwen, 1419.\n"
@@ -1,8 +1,8 @@
1
- module Shire
2
- module VERSION
1
+ module Shire #:nodoc:
2
+ module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 1
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: shire
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.1
7
- date: 2006-12-07 00:00:00 +00:00
6
+ version: 0.1.0
7
+ date: 2006-12-17 00:00:00 +00:00
8
8
  summary: Shire time.
9
9
  require_paths:
10
10
  - lib
@@ -36,20 +36,20 @@ files:
36
36
  - lib/shire/core_ext
37
37
  - lib/shire/core_ext.rb
38
38
  - lib/shire/version.rb
39
- - lib/shire/core_ext/date
40
39
  - lib/shire/core_ext/date.rb
41
40
  - lib/shire/core_ext/time
42
41
  - lib/shire/core_ext/time.rb
43
42
  - lib/shire/core_ext/time/calculations.rb
44
43
  - lib/shire/core_ext/time/constants.rb
44
+ - bin/shire
45
45
  test_files: []
46
46
 
47
47
  rdoc_options: []
48
48
 
49
49
  extra_rdoc_files: []
50
50
 
51
- executables: []
52
-
51
+ executables:
52
+ - shire
53
53
  extensions: []
54
54
 
55
55
  requirements: []