twelve_days_of_christmas 0.0.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.
- checksums.yaml +7 -0
- data/bin/run +3 -0
- data/lib/twelve_days_of_christmas/gift.rb +32 -0
- data/lib/twelve_days_of_christmas/line.rb +40 -0
- data/lib/twelve_days_of_christmas/number.rb +37 -0
- data/lib/twelve_days_of_christmas/song.rb +15 -0
- data/lib/twelve_days_of_christmas/verse.rb +33 -0
- data/lib/twelve_days_of_christmas.rb +8 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5dbb33bb0bdefa5f682dadb5195ca28d5e9afcac1b419090883b2b3a4ccb2e29
|
4
|
+
data.tar.gz: d3d612304a33789f8c99c78c0e1ef7c3d7261aa960ed410b52f001a530533039
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f7b34714c28d648da099f79da2bd16ed5a89ca9a9031b79b23152066cb80a3888527767f34245981edc19cdd506f07fe5cf6b7597fce22395e0c8fa9cf619289
|
7
|
+
data.tar.gz: 7bafd475900c54494a7a66cdd3b3a50306cbb887525fa65ff56eaf96635312bc24e5e9924c711626d7841bf3c804bc1ae8132148f32b07b23d8c4ed1fd8fdf06
|
data/bin/run
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module TwelveDaysOfChristmas
|
2
|
+
|
3
|
+
class Gift
|
4
|
+
|
5
|
+
def initialize(day)
|
6
|
+
@day = day
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_text
|
10
|
+
"#{Number.new(@day).to_article} #{self.class.list[@day-1]}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.list
|
14
|
+
[
|
15
|
+
"partridge in a pear tree",
|
16
|
+
"turtle doves",
|
17
|
+
"french hens",
|
18
|
+
"calling birds",
|
19
|
+
"golden rings",
|
20
|
+
"geese-a-laying",
|
21
|
+
"swans-a-swimming",
|
22
|
+
"maids-a-milking",
|
23
|
+
"ladies dancing",
|
24
|
+
"lords-a-leaping",
|
25
|
+
"pipers piping",
|
26
|
+
"drummers drumming"
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module TwelveDaysOfChristmas
|
2
|
+
|
3
|
+
class Line
|
4
|
+
|
5
|
+
def initialize(line, lines)
|
6
|
+
@line = line
|
7
|
+
@lines = lines
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_human
|
11
|
+
[prefix, @line].compact.join(" ") + punctuation
|
12
|
+
end
|
13
|
+
|
14
|
+
def punctuation
|
15
|
+
if first?
|
16
|
+
":"
|
17
|
+
elsif last?
|
18
|
+
"."
|
19
|
+
else
|
20
|
+
","
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def prefix
|
25
|
+
"and" if last?
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def first?
|
31
|
+
@line == @lines[0]
|
32
|
+
end
|
33
|
+
|
34
|
+
def last?
|
35
|
+
@line == @lines[-1]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module TwelveDaysOfChristmas
|
2
|
+
|
3
|
+
class Number
|
4
|
+
|
5
|
+
def initialize(number)
|
6
|
+
@number = number
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_ordinal
|
10
|
+
@number.to_s + ordinal_ending
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_article
|
14
|
+
@number == 1 ? "a" : @number
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def ordinal_ending
|
20
|
+
self.class.custom_ordinal_endings[@number] || self.class.default_ordinal_ending
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.custom_ordinal_endings
|
24
|
+
{
|
25
|
+
1 => "st",
|
26
|
+
2 => "nd",
|
27
|
+
3 => "rd"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.default_ordinal_ending
|
32
|
+
"th"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module TwelveDaysOfChristmas
|
2
|
+
|
3
|
+
class Verse
|
4
|
+
|
5
|
+
def initialize(day)
|
6
|
+
@day = day
|
7
|
+
end
|
8
|
+
|
9
|
+
def output
|
10
|
+
lines.map { |l| Line.new(l, lines).to_human }.join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def lines
|
16
|
+
[intro_line, gift_lines].flatten
|
17
|
+
end
|
18
|
+
|
19
|
+
def intro_line
|
20
|
+
"On the #{Number.new(@day).to_ordinal} day of Christmas my true love gave to me"
|
21
|
+
end
|
22
|
+
|
23
|
+
def gift_lines
|
24
|
+
(1..@day).to_a.reverse.map { |d| Gift.new(d).to_text }
|
25
|
+
end
|
26
|
+
|
27
|
+
def included_days
|
28
|
+
1..@day
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twelve_days_of_christmas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Laney Stroup
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This is a fun attempt at refactoring the song "The Twelve Days of Christmas."
|
14
|
+
email: laney@stroupsolutions.com
|
15
|
+
executables:
|
16
|
+
- run
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/run
|
21
|
+
- lib/twelve_days_of_christmas.rb
|
22
|
+
- lib/twelve_days_of_christmas/gift.rb
|
23
|
+
- lib/twelve_days_of_christmas/line.rb
|
24
|
+
- lib/twelve_days_of_christmas/number.rb
|
25
|
+
- lib/twelve_days_of_christmas/song.rb
|
26
|
+
- lib/twelve_days_of_christmas/verse.rb
|
27
|
+
homepage: https://github.com/laneystroup/twelve_days_of_christmas
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.0.9
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: The Twelve Days of Christmas, Refactored
|
50
|
+
test_files: []
|