i18n-date 0.0.5 → 0.0.6
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/lib/i18n-date/version.rb +1 -1
- data/lib/i18n-date.rb +5 -0
- data/spec/date_spec.rb +7 -0
- metadata +1 -1
data/lib/i18n-date/version.rb
CHANGED
data/lib/i18n-date.rb
CHANGED
@@ -11,6 +11,8 @@ class Date
|
|
11
11
|
end
|
12
12
|
|
13
13
|
private
|
14
|
+
|
15
|
+
NonValidObject = 'Invalid object, it should be a String'
|
14
16
|
|
15
17
|
PREPOSITIONS = (%w/de/) if !Object.const_defined?('PREPOSITIONS')
|
16
18
|
|
@@ -58,6 +60,9 @@ class Date
|
|
58
60
|
end
|
59
61
|
|
60
62
|
def self.month_to_english(string)
|
63
|
+
|
64
|
+
raise NonValidObject if string.nil? || !string.kind_of?(String)
|
65
|
+
|
61
66
|
string = remove_prepositions(string) # remove prepositions
|
62
67
|
matching_month = string.match(/[\w]+[^\d],\s(?<date>.*)$/)
|
63
68
|
# just for dates that have day name and then current date
|
data/spec/date_spec.rb
CHANGED
@@ -30,4 +30,11 @@ describe Date do
|
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
|
+
it "should return an error message when object to parse is not a string" do
|
34
|
+
begin
|
35
|
+
Date.month_to_english(1)
|
36
|
+
rescue RuntimeError => e
|
37
|
+
e.to_s.should be_eql('Invalid object, it should be a String')
|
38
|
+
end
|
39
|
+
end
|
33
40
|
end
|