tomafro-jekyll 0.5.3.1 → 0.5.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jekyll/filters.rb +13 -0
- data/test/test_filters.rb +6 -0
- metadata +1 -1
data/lib/jekyll/filters.rb
CHANGED
@@ -28,6 +28,19 @@ module Jekyll
|
|
28
28
|
def number_of_words(input)
|
29
29
|
input.split.length
|
30
30
|
end
|
31
|
+
|
32
|
+
def ordinalize(number)
|
33
|
+
if (11..13).include?(number.to_i % 100)
|
34
|
+
"#{number}th"
|
35
|
+
else
|
36
|
+
case number.to_i % 10
|
37
|
+
when 1; "#{number}st"
|
38
|
+
when 2; "#{number}nd"
|
39
|
+
when 3; "#{number}rd"
|
40
|
+
else "#{number}th"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
31
44
|
|
32
45
|
def array_to_sentence_string(array)
|
33
46
|
connector = "and"
|
data/test/test_filters.rb
CHANGED
@@ -45,5 +45,11 @@ class TestFilters < Test::Unit::TestCase
|
|
45
45
|
should "escape special characters" do
|
46
46
|
assert_equal "hey%21", @filter.cgi_escape("hey!")
|
47
47
|
end
|
48
|
+
|
49
|
+
should "ordinalize numbers" do
|
50
|
+
assert_equal "1st", @filter.ordinalize(1)
|
51
|
+
assert_equal "113th", @filter.ordinalize(113)
|
52
|
+
assert_equal "502nd", @filter.ordinalize(502)
|
53
|
+
end
|
48
54
|
end
|
49
55
|
end
|