ddate-redux 1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94280960418b87209dad25d98065f11faedafc01
4
+ data.tar.gz: 1e811f9c81252750152d353b160c52b6a1e20e6d
5
+ SHA512:
6
+ metadata.gz: 4c1ca575cd1f54afc5a75bf14fc6c25d44a634c826dd8f4cbbd53c636bda9dd33cae88383168e8d3707b24f6196f34ea628ce24b3b59f5266ee0a18bf33d3a59
7
+ data.tar.gz: 1c325e92c3b60d652fdc26ec4278d2e8ed108518dca3ff26b54dc6aaffb48f22f226e3d182ed5589ceb8f97ae8bc94731a0206305c7aed9785f25dcfc42e8081
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ddate.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tamara Temple
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Ddate
2
+
3
+ The old unix systems used to come with a ddate command that gave the
4
+ Discordian Date, usually something like
5
+
6
+ Sweetmorn, Bureaucracy 42, 3161 YOLD
7
+
8
+ This is a reimplementation in ruby, FNAR.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'ddate'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install ddate
23
+
24
+ ## Usage
25
+
26
+ Try:
27
+
28
+ $ ddate -h
29
+
30
+ Otherwise the command line is basically the same as the old ddate(1) program:
31
+
32
+ $ ddate [ -h | -f | -v ] [+format] [day month year]
33
+
34
+ Use `-f` to see the formatting options.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/tamouse/ddate/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
43
+
44
+ ## References
45
+
46
+ * [Discordian Calendar](https://en.wikipedia.org/wiki/Discordian_calendar) at wikipedia.
47
+ * [Principia Discordia Calendar Converter](http://principiadiscordia.com/book/41.php)
48
+ * [C implementation of ddate(1)](https://github.com/bo0ts/ddate)
49
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/ddate ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path('../lib', __FILE__))
3
+ require 'rubygems'
4
+ require 'ddate'
5
+ runner = Ddate::CLI.new
6
+ begin
7
+ puts runner.run(ARGV)
8
+ rescue DdateException => e
9
+ STDERR.puts "Error: #{e}"
10
+ STDERR.puts Ddate::USAGE
11
+ end
data/ddate.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ddate/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = Ddate::PACKAGE
8
+ spec.version = Ddate::VERSION
9
+ spec.authors = Ddate::AUTHORS
10
+ spec.email = Ddate::EMAILS
11
+ spec.summary = %q{discordian date, in ruby}
12
+ spec.description = %q{reimplement the ddate unix command, in ruby}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "awesome_print"
26
+
27
+ spec.add_dependency "activesupport"
28
+ end
data/lib/ddate.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'date'
2
+ require 'active_support/core_ext/integer/inflections'
3
+
4
+ require 'ddate/version'
5
+ require 'ddate/converter'
6
+ require 'ddate/formatter'
7
+ require 'ddate/cli'
8
+
9
+ class DdateException < StandardError; end
10
+
11
+ module Ddate
12
+
13
+ end
data/lib/ddate/cli.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'singleton'
2
+
3
+ module Ddate
4
+ class CLI
5
+
6
+ FORMAT_RE = %r{\A\+(.*)\z}
7
+ OPTION_RE = %r{\A\-(\S)\z}
8
+
9
+ attr_accessor :formatter
10
+
11
+ def initialize
12
+ self.formatter = Ddate::Formatter.new
13
+ end
14
+
15
+ def run(args)
16
+
17
+ num_args = args.count
18
+ case num_args
19
+ when 0
20
+ # no arguments, run with today's date
21
+ today = Date.today
22
+ year, month, day = today.year, today.month, today.day
23
+ when 1
24
+ arg = args.shift.to_s
25
+ if (help = arg.to_s.match(OPTION_RE) {|m| handle_options($1)})
26
+ return help
27
+ elsif (self.formatter = arg.to_s.match(FORMAT_RE) {|m| Ddate::Formatter.new($1)})
28
+ # do nothing, drop through
29
+ else
30
+ raise DdateException.new "not enough arguments"
31
+ end
32
+ today = Date.today
33
+ year, month, day = today.year, today.month, today.day
34
+ when 3
35
+ day, month, year = args.map { |i| Integer(i) }
36
+ when 4
37
+ fmt = args.shift.to_s
38
+ if (self.formatter = fmt.match(FORMAT_RE) {|m| Ddate::Formatter.new($1)})
39
+ # do nothing, drop through
40
+ else
41
+ raise DdateException.new "first argument when 4 given must be a format"
42
+ end
43
+ day, month, year = args.map { |i| Integer(i) }
44
+ else
45
+ raise DdateException.new "wrong number of arguments"
46
+ end
47
+ Ddate::Converter.new(year, month, day, formatter).to_s
48
+ end
49
+
50
+ def handle_options(option)
51
+ case option.downcase
52
+ when 'h'
53
+ Ddate::USAGE
54
+ when 'f'
55
+ Ddate::FORMATTER_USAGE
56
+ when 'v'
57
+ Ddate::VERSION_STRING
58
+ else
59
+ raise DdateException.new "unknown option: #{option}"
60
+ end
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,186 @@
1
+ module Ddate
2
+ class Converter
3
+
4
+ YOLD_BASE = 1970
5
+ YOLD_OFFSET = 1166
6
+ CALENDAR_DAYS_PER_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
7
+
8
+ DAYS_PER_WEEK = 5
9
+ DAYS_LONG = %w[Sweetmorn Boomtime Pungenday Prickle-Prickle Setting\ Orange]
10
+ DAYS_SHORT = %w[SM BT PD PP SO]
11
+
12
+ # Season are 73 days, 4 per 365 year
13
+ DAYS_PER_SEASON = 73
14
+ SEASONS_LONG = %w[Chaos Discord Confusion Bureaucracy The\ Aftermath]
15
+ SEASONS_SHORT = %w[Chs Dsc Cfn Bcy Afm]
16
+
17
+ APOSTLE_HOLIDAY = 4
18
+ APOSTLE_HOLIDAYS = %w[Mungday Mojoday Syaday Zaraday Maladay] # fifth of season
19
+ SEASON_HOLIDAY = 49
20
+ SEASON_HOLIDAYS = %w[Choaflux Discoflux Confuflux Bureflux Afflux] # 50th of season
21
+
22
+ ST_TIBS_DAY = "Feast of St. Tib's Day" # once every 4 years, inserted between 59 and 60 Season of Chaos
23
+
24
+ EXCLAMATIONS = [
25
+ 'Hail Eris!',
26
+ 'All Hail Discordia!',
27
+ 'Kallisti!',
28
+ 'Fnord.',
29
+ 'Or not.',
30
+ 'Wibble.',
31
+ 'Pzat!',
32
+ "P'tang!",
33
+ 'Frink!',
34
+ 'Slack!',
35
+ "Praise \"Bob\"!",
36
+ 'Or kill me.',
37
+ 'Grudnuk demand sustenance!',
38
+ 'Keep the Lasagna flying!',
39
+ 'You are what you see.',
40
+ 'Or is it?',
41
+ 'This statement is false.',
42
+ 'Lies and slander, sire!',
43
+ 'Hee hee hee!',
44
+ ''
45
+ ]
46
+ LINUX_EXCLAMATIONS = [
47
+ 'Hail Eris, Hack Linux!',
48
+ ]
49
+ NON_LINUX_EXCLAMATIONS = [
50
+ 'This Fruit is not the True Fruit of Discord.',
51
+ ]
52
+
53
+ KILL_BOB_DATE = Date.new(8661, 6, 5)
54
+
55
+ attr_accessor :formatter
56
+ attr_reader :year, :yday, :day, :season
57
+
58
+ private
59
+ attr_accessor :date
60
+ attr_writer :year, :yday, :day, :season
61
+
62
+ public
63
+
64
+ def initialize(year, month, day, formatter = nil)
65
+ self.date = Date.new(year, month, day)
66
+ self.formatter = formatter || Ddate::Formatter.new
67
+ convert
68
+ end
69
+
70
+ def convert
71
+ self.year = DY(date.year)
72
+ self.day = date.yday - 1
73
+
74
+ if leapyear?
75
+ if day == 59
76
+ self.day = :st_tibs
77
+ elsif day > 59
78
+ self.day = day - 1
79
+ end
80
+ end
81
+
82
+ self.yday = day
83
+ self.season = 0
84
+ unless day == :st_tibs
85
+ while (day >= DAYS_PER_SEASON) do
86
+ self.season = season + 1
87
+ self.day = day - DAYS_PER_SEASON
88
+ end
89
+ end
90
+
91
+ self
92
+ end
93
+
94
+ def to_s
95
+ if st_tibs?
96
+ dayactual = nil
97
+ dayordinal = nil
98
+ format = :sttibs
99
+ else
100
+ dayactual = day+1
101
+ dayordinal = dayactual.ordinalize
102
+ format = :standard
103
+ end
104
+
105
+ format_arguments = {
106
+ year: year,
107
+ day: dayactual,
108
+ dayth: dayordinal,
109
+ dayname: dayname,
110
+ dayname_short: dayname_short,
111
+ seasonname: seasonname,
112
+ seasonname_short: seasonname_short,
113
+ holiday: holiday,
114
+ exclaim: exclaim,
115
+ kill_bob: kill_bob,
116
+ st_tibs_day: ST_TIBS_DAY
117
+ }
118
+
119
+ formatted = formatter.split(format).map do |part|
120
+ part % format_arguments
121
+ end
122
+
123
+ if holiday.nil? && formatted.count > 1
124
+ formatted.pop
125
+ end
126
+
127
+ formatted.compact.join
128
+ end
129
+
130
+ def leapyear?
131
+ (year % 4) == 2
132
+ end
133
+
134
+ def weekday
135
+ yday % 5
136
+ end
137
+
138
+ def dayname
139
+ DAYS_LONG[weekday] unless st_tibs?
140
+ end
141
+
142
+ def dayname_short
143
+ DAYS_SHORT[weekday] unless st_tibs?
144
+ end
145
+
146
+ def seasonname
147
+ SEASONS_LONG[season]
148
+ end
149
+
150
+ def seasonname_short
151
+ SEASONS_SHORT[season]
152
+ end
153
+
154
+ def st_tibs?
155
+ day == :st_tibs
156
+ end
157
+
158
+ def holiday
159
+ if day == 4
160
+ APOSTLE_HOLIDAYS[season]
161
+ elsif day == 49
162
+ SEASON_HOLIDAYS[season]
163
+ end
164
+ end
165
+
166
+ def exclaim
167
+ @exclaims ||= if `uname`.chomp.downcase == 'linux'
168
+ EXCLAMATIONS.concat(LINUX_EXCLAMATIONS)
169
+ else
170
+ EXCLAMATIONS.concat(NON_LINUX_EXCLAMATIONS)
171
+ end
172
+ @exclaims.sample
173
+ end
174
+
175
+ def kill_bob
176
+ (KILL_BOB_DATE - @date).to_i
177
+ end
178
+
179
+ private
180
+
181
+ def DY(year)
182
+ year + YOLD_OFFSET
183
+ end
184
+
185
+ end
186
+ end
@@ -0,0 +1,36 @@
1
+ module Ddate
2
+ class Formatter
3
+
4
+ STTIBS_RE = %r|%{(.*?)%}|
5
+
6
+ SPLIT_STOP = '%%N'
7
+
8
+ DEFAULT_FORMAT = '%{%A, %B the %e%}, YOLD %Y.%N Celebrate %H!'
9
+
10
+ attr_reader :standard, :sttibs
11
+
12
+ def initialize(format = nil)
13
+ format = DEFAULT_FORMAT if format.to_s.empty?
14
+ @standard = create_format_string_from(format.gsub(STTIBS_RE){$1})
15
+ @sttibs = create_format_string_from(format.gsub(STTIBS_RE, '%{st_tibs_day}'))
16
+ end
17
+
18
+ def create_format_string_from(format_string)
19
+ format_string.gsub(/%[AaBbdeHNntY.X]/, {
20
+ '%A' => '%{dayname}', '%a' => '%{dayname_short}',
21
+ '%B' => '%{seasonname}', '%b' => '%{seasonname_short}',
22
+ '%d' => '%{day}', '%e' => '%{dayth}',
23
+ '%H' => '%{holiday}', '%N' => SPLIT_STOP,
24
+ '%n' => "\n", '%t' => "\t",
25
+ '%Y' => '%{year}', '%.' => '%{exclaim}',
26
+ '%X' => '%{kill_bob}',
27
+ } )
28
+
29
+ end
30
+
31
+ def split(key)
32
+ send(key).split(SPLIT_STOP, 2)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Ddate
3
+ VERSION = '1.0.3'
4
+
5
+ AUTHORS = ['Tamara Temple']
6
+ EMAILS = ['tamouse@gmail.com']
7
+ HOMEPAGE = 'https://github.com/tamouse/ddate-redux'
8
+ LICENSE = 'MIT'
9
+
10
+ PACKAGE = 'ddate-redux'
11
+ PROGNAME = File.basename($0)
12
+ VERSION_STRING = "#{PROGNAME}: #{PACKAGE} #{VERSION}"
13
+ USAGE = "Usage: #{PROGNAME} [ -h | -v ] [+format] [day month year]"
14
+ FORMATTER_USAGE = %q[
15
+
16
+ Format strings work just like the old ddate(1) program:
17
+
18
+ If a format string is specified, the Discordian date will be printed in
19
+ a format specified by the string. This mechanism works similarly to the
20
+ format string mechanism of date(1), only almost completely differently.
21
+ The fields are:
22
+
23
+ %A Full name of the day of the week (i.e., Sweetmorn)
24
+
25
+ %a Abbreviated name of the day of the week (i.e., SM)
26
+
27
+ %B Full name of the season (i.e., Chaos)
28
+
29
+ %b Abbreviated name of the season (i.e., Chs)
30
+
31
+ %d Ordinal number of day in season (i.e., 23)
32
+
33
+ %e Cardinal number of day in season (i.e., 23rd)
34
+
35
+ %H Name of current Holyday, if any
36
+
37
+ %N Magic code to prevent rest of format from being printed unless
38
+ today is a Holyday.
39
+
40
+ %n Newline
41
+
42
+ %t Tab
43
+
44
+ %X Number of days remaining until X-Day. (Not valid if the SubGe-
45
+ nius options are not compiled in.)
46
+
47
+ %{
48
+
49
+ %} Used to enclose the part of the string which is to be replaced
50
+ with the words "St. Tib’s Day" if the current day is St. Tib’s
51
+ Day.
52
+
53
+ %. Try it and see.
54
+
55
+ Examples:
56
+
57
+ % ddate
58
+ Sweetmorn, Bureaucracy 42, 3161 YOLD
59
+
60
+ % ddate +’Today is %{%A, the %e of %B%}, %Y. %N%nCelebrate %H’
61
+ Today is Sweetmorn, the 42nd of Bureaucracy, 3161.
62
+
63
+ % ddate +"It’s %{%A, the %e of %B%}, %Y. %N%nCelebrate %H" 26 9 1995
64
+ It’s Prickle-Prickle, the 50th of Bureaucracy, 3161.
65
+ Celebrate Bureflux
66
+
67
+ % ddate +"Today’s %{%A, the %e of %B%}, %Y. %N%nCelebrate %H" 29 2 1996
68
+ Today’s St. Tib’s Day, 3162.
69
+
70
+ ]
71
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddate
4
+
5
+ describe CLI do
6
+
7
+ before(:all) do
8
+ DateStruct = Struct.new :year, :month, :day
9
+ end
10
+
11
+ let(:ddate_runner) {Ddate::CLI.new}
12
+
13
+ it 'reports today with no arguments' do
14
+ year, month, day = 2014, 7, 3
15
+ today = DateStruct.new year, month, day
16
+ allow(Date).to receive(:today).and_return(today)
17
+ args = []
18
+ expect(ddate_runner.run(args)).to eq("Prickle-Prickle, Confusion the 38th, YOLD 3180.")
19
+ end
20
+
21
+ it 'gives usage' do
22
+ expect(ddate_runner.run(['-h'])).to eq(Ddate::USAGE)
23
+ end
24
+
25
+ it 'gives format usage' do
26
+ expect(ddate_runner.run(['-f'])).to eq(Ddate::FORMATTER_USAGE)
27
+ end
28
+
29
+ it 'gives version string' do
30
+ expect(ddate_runner.run(['-v'])).to eq(Ddate::VERSION_STRING)
31
+ end
32
+
33
+ it 'gives today in another format' do
34
+ format = '+%{%a %b %d%} %Y'
35
+ today = DateStruct.new 2014, 7, 28
36
+ expected = 'PP Cfn 63 3180'
37
+ allow(Date).to receive(:today).and_return(today)
38
+ expect(ddate_runner.run([format])).to eq(expected)
39
+ end
40
+
41
+ it 'prints st tibs' do
42
+ expected = "Feast of St. Tib's Day, YOLD 3162."
43
+ expect(ddate_runner.run([29, 2, 1996])).to eq(expected)
44
+ end
45
+
46
+ it 'handles format and date' do
47
+ format = '+%{%a %b %d%} %Y'
48
+ expected = 'PP Cfn 63 3180'
49
+ year, month, day = 2014, 7, 28
50
+ args = [format, day, month, year]
51
+ expect(ddate_runner.run(args)).to eq(expected)
52
+ end
53
+
54
+ it 'should print st tibs day in an alternate format' do
55
+ format = "+Today's %{%A, the %e of %B%}, %Y.%N%nCelebrate %H"
56
+ expected = "Today's Feast of St. Tib's Day, 3162."
57
+ args = [format, 29, 2, 1996]
58
+ expect(ddate_runner.run(args)).to eq(expected)
59
+ end
60
+
61
+ it 'should show the count down until kill bob day' do
62
+ expect(ddate_runner.run(['+%X', 4, 6, 8661])).to eq('1')
63
+ end
64
+
65
+ it 'should make an exclamation' do
66
+ result = ddate_runner.run(['+%.'])
67
+ exclamations = Ddate::Converter::EXCLAMATIONS +
68
+ Ddate::Converter::LINUX_EXCLAMATIONS +
69
+ Ddate::Converter::NON_LINUX_EXCLAMATIONS
70
+ expect(exclamations).to include(result)
71
+ end
72
+
73
+
74
+
75
+ describe 'error paths' do
76
+ let(:dr) {Ddate::CLI.new}
77
+ it 'should raise an error with invalid option' do
78
+ expect{dr.run([-x])}.to raise_error
79
+ end
80
+ it 'should raise an error with an empty argument' do
81
+ expect{dr.run([''])}.to raise_error
82
+ end
83
+ it 'should raise an error with 2 arguments' do
84
+ expect{dr.run([1, 2])}.to raise_error
85
+ end
86
+ it 'should raise an error with 4 arguments but no format' do
87
+ expect{dr.run([1, 2, 3, 4])}.to raise_error
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddate
4
+
5
+ describe Converter do
6
+
7
+ [1972, 1996, 2012].each do |year|
8
+ it "#{year} should be a leap year" do
9
+ expect(Ddate::Converter.new(year, 1, 1).leapyear?).to eq(true)
10
+ end
11
+ end
12
+
13
+ [1971, 2014, 2015, 2017].each do |year|
14
+ it "#{year} should NOT be a leap year" do
15
+ expect(Ddate::Converter.new(year, 1, 1).leapyear?).not_to eq(true)
16
+ end
17
+ end
18
+
19
+ it "should convert 2014-01-01" do
20
+ ddate = Ddate::Converter.new(2014, 1, 1)
21
+ expect(ddate.year).to eq(2014+1166)
22
+ expect(ddate.day).to eq(0)
23
+ expect(ddate.season).to eq(0)
24
+ expect(ddate.to_s).to eq("Sweetmorn, Chaos the 1st, YOLD #{2014+1166}.")
25
+ end
26
+
27
+ it "should convert 1972-07-23" do
28
+ ddate = Ddate::Converter.new(1972, 7, 23)
29
+ expect(ddate.year).to eq(1972+1166)
30
+ expect(ddate.day).to eq(57)
31
+ expect(ddate.season).to eq(2)
32
+ expect(ddate.leapyear?).to eq(true)
33
+ expect(ddate.to_s).to eq("Prickle-Prickle, Confusion the 58th, YOLD 3138.")
34
+ end
35
+
36
+ it "should convert 1993-12-31" do
37
+ ddate = Ddate::Converter.new(1993, 12, 31)
38
+ expect(ddate.year).to eq(1993+1166)
39
+ expect(ddate.day).to eq(72)
40
+ expect(ddate.season).to eq(4)
41
+ expect(ddate.to_s).to eq("Setting Orange, The Aftermath the 73rd, YOLD 3159.")
42
+ end
43
+
44
+ it "should get st. tib's day right" do
45
+ ddate = Ddate::Converter.new(2012,2,29)
46
+ expect(ddate.year).to eq(2012+1166)
47
+ expect(ddate.leapyear?).to eq(true)
48
+ expect(ddate.day).to eq(:st_tibs)
49
+ expect(ddate.season).to eq(0)
50
+ expect(ddate.to_s).to eq("Feast of St. Tib's Day, YOLD #{2012+1166}.")
51
+ end
52
+
53
+ it "should get day after st. tib's day right" do
54
+ ddate = Ddate::Converter.new(2012,3,1)
55
+ expect(ddate.year).to eq(2012+1166)
56
+ expect(ddate.day).to eq(59)
57
+ expect(ddate.season).to eq(0)
58
+ expect(ddate.to_s).to eq("Setting Orange, Chaos the 60th, YOLD 3178.")
59
+ end
60
+
61
+ it "should get last day of leap year right, too" do
62
+ ddate = Ddate::Converter.new(2012, 12, 31)
63
+ expect(ddate.year).to eq(2012+1166)
64
+ expect(ddate.day).to eq(72)
65
+ expect(ddate.season).to eq(4)
66
+ expect(ddate.to_s).to eq("Setting Orange, The Aftermath the 73rd, YOLD 3178.")
67
+ end
68
+
69
+ it "should get season holiday right" do
70
+ ddate = Ddate::Converter.new(1995, 9, 26)
71
+ expect(ddate.to_s).to eq("Prickle-Prickle, Bureaucracy the 50th, YOLD 3161. Celebrate Bureflux!")
72
+ end
73
+
74
+ it 'should get saint day right' do
75
+ ddate = Ddate::Converter.new(1995, 1, 5)
76
+ expect(ddate.to_s).to eq('Setting Orange, Chaos the 5th, YOLD 3161. Celebrate Mungday!')
77
+ end
78
+
79
+ end
80
+
81
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Ddate
4
+
5
+ describe Formatter do
6
+
7
+ it "creates default formatter" do
8
+ formatter = Ddate::Formatter.new
9
+ expect(formatter.standard).to eq("%{dayname}, %{seasonname} the %{dayth}, YOLD %{year}.#{Ddate::Formatter::SPLIT_STOP} Celebrate %{holiday}!")
10
+ expect(formatter.sttibs).to eq("%{st_tibs_day}, YOLD %{year}.#{Ddate::Formatter::SPLIT_STOP} Celebrate %{holiday}!")
11
+ end
12
+
13
+ it 'creates an alternative formatter' do
14
+ format = 'Today is %{%A %B %d%}, %Y YOLD%N%nCelebrate %H!'
15
+ formatter = Ddate::Formatter.new(format)
16
+ expect(formatter.standard).to eq("Today is %{dayname} %{seasonname} %{day}, %{year} YOLD#{Ddate::Formatter::SPLIT_STOP}\nCelebrate %{holiday}!")
17
+ expect(formatter.sttibs).to eq("Today is %{st_tibs_day}, %{year} YOLD#{Ddate::Formatter::SPLIT_STOP}\nCelebrate %{holiday}!")
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+
3
+ =begin
4
+
5
+ describe Ddate do
6
+
7
+ [1970, 2014].each do |year|
8
+ it "#{year} should be a leap year" do
9
+ expect(Ddate.new(year, 1, 1).leapyear?).to eq(true)
10
+ end
11
+ end
12
+
13
+ [1971, 2015, 2016, 2017].each do |year|
14
+ it "#{year} should NOT be a leap year" do
15
+ expect(Ddate.new(year, 1, 1).leapyear?).not_to eq(true)
16
+ end
17
+ end
18
+
19
+ it "should convert 2014-01-01" do
20
+ ddate = Ddate.new(2014, 1, 1)
21
+ expect(ddate.year).to eq(2014+1166)
22
+ expect(ddate.day).to eq(0)
23
+ expect(ddate.season).to eq(0)
24
+ expect(ddate.to_s).to eq("Sweetmorn, Chaos, 1st, #{2014+1166} YOLD")
25
+ end
26
+
27
+ it "should convert 1970-07-23" do
28
+ ddate = Ddate.new(1970, 7, 23)
29
+ expect(ddate.year).to eq(1970+1166)
30
+ expect(ddate.day).to eq(56) # cos it's a leapyear
31
+ expect(ddate.season).to eq(2)
32
+ end
33
+
34
+ it "should convert 1993-12-31" do
35
+ ddate = Ddate.new(1993, 12, 31)
36
+ expect(ddate.year).to eq(1993+1166)
37
+ expect(ddate.day).to eq(72)
38
+ expect(ddate.season).to eq(4)
39
+ end
40
+
41
+ it "should get st. tib's day right" do
42
+ ddate = Ddate.new(2014,3,1)
43
+ expect(ddate.year).to eq(2014+1166)
44
+ expect(ddate.leapyear?).to eq(true)
45
+ expect(ddate.day).to eq(:st_tibs)
46
+ expect(ddate.season).to eq(0)
47
+ expect(ddate.to_s).to eq("Feast of St. Tib's, #{2014+1166} YOLD")
48
+ end
49
+
50
+ it "should get day after st. tib's day right" do
51
+ ddate = Ddate.new(2014,3,2)
52
+ expect(ddate.year).to eq(2014+1166)
53
+ expect(ddate.day).to eq(59)
54
+ expect(ddate.season).to eq(0)
55
+ end
56
+
57
+ it "should get last day of leap year right, too" do
58
+ ddate = Ddate.new(2014, 12, 31)
59
+ STDERR.puts ddate.inspect
60
+ expect(ddate.year).to eq(2014+1166)
61
+ expect(ddate.day).to eq(71)
62
+ expect(ddate.season).to eq(4)
63
+ end
64
+
65
+ it "should get season holiday right" do
66
+ ddate = Ddate.new(1995, 9, 26)
67
+ expect(ddate.to_s).to eq("Bureflux, Setting Orange, Bureaucracy, 50th, 3161 YOLD")
68
+ end
69
+ end
70
+
71
+ =end
@@ -0,0 +1,81 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
79
+
80
+ require 'ddate'
81
+ require 'pry'
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ddate-redux
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Tamara Temple
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: awesome_print
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: reimplement the ddate unix command, in ruby
98
+ email:
99
+ - tamouse@gmail.com
100
+ executables:
101
+ - ddate
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".ruby-version"
108
+ - Gemfile
109
+ - Guardfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/ddate
114
+ - ddate.gemspec
115
+ - lib/ddate.rb
116
+ - lib/ddate/cli.rb
117
+ - lib/ddate/converter.rb
118
+ - lib/ddate/formatter.rb
119
+ - lib/ddate/version.rb
120
+ - spec/lib/ddate/cli_spec.rb
121
+ - spec/lib/ddate/converter_spec.rb
122
+ - spec/lib/ddate/formatter_spec.rb
123
+ - spec/lib/ddate_spec.rb
124
+ - spec/spec_helper.rb
125
+ homepage: ''
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.2.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: discordian date, in ruby
149
+ test_files:
150
+ - spec/lib/ddate/cli_spec.rb
151
+ - spec/lib/ddate/converter_spec.rb
152
+ - spec/lib/ddate/formatter_spec.rb
153
+ - spec/lib/ddate_spec.rb
154
+ - spec/spec_helper.rb