lazier 3.5.7 → 4.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.travis-gemfile +5 -4
  3. data/.travis.yml +2 -2
  4. data/CHANGELOG.md +65 -8
  5. data/Gemfile +9 -8
  6. data/README.md +4 -0
  7. data/doc/Lazier.html +178 -110
  8. data/doc/Lazier/Boolean.html +7 -7
  9. data/doc/Lazier/Configuration.html +24 -50
  10. data/doc/Lazier/DateTime.html +50 -305
  11. data/doc/Lazier/DateTime/ClassMethods.html +116 -806
  12. data/doc/Lazier/Exceptions.html +2 -2
  13. data/doc/Lazier/Exceptions/Debug.html +1 -1
  14. data/doc/Lazier/Exceptions/MissingTranslation.html +18 -14
  15. data/doc/Lazier/Exceptions/TranslationExceptionHandler.html +213 -0
  16. data/doc/Lazier/Hash.html +19 -155
  17. data/doc/Lazier/I18n.html +1735 -230
  18. data/doc/Lazier/Math.html +1 -1
  19. data/doc/Lazier/Math/ClassMethods.html +13 -13
  20. data/doc/Lazier/Object.html +353 -339
  21. data/doc/Lazier/Pathname.html +4 -4
  22. data/doc/Lazier/Settings.html +150 -304
  23. data/doc/Lazier/String.html +39 -199
  24. data/doc/Lazier/TimeZone.html +244 -746
  25. data/doc/Lazier/TimeZone/ClassMethods.html +109 -127
  26. data/doc/Lazier/Version.html +4 -4
  27. data/doc/_index.html +15 -15
  28. data/doc/class_list.html +1 -1
  29. data/doc/file.README.html +5 -1
  30. data/doc/index.html +5 -1
  31. data/doc/method_list.html +97 -169
  32. data/doc/top-level-namespace.html +1 -1
  33. data/lazier.gemspec +9 -6
  34. data/lib/lazier.rb +41 -50
  35. data/lib/lazier/boolean.rb +0 -1
  36. data/lib/lazier/configuration.rb +26 -28
  37. data/lib/lazier/datetime.rb +33 -127
  38. data/lib/lazier/exceptions.rb +14 -6
  39. data/lib/lazier/hash.rb +7 -15
  40. data/lib/lazier/i18n.rb +130 -48
  41. data/lib/lazier/math.rb +6 -7
  42. data/lib/lazier/object.rb +79 -97
  43. data/lib/lazier/pathname.rb +0 -1
  44. data/lib/lazier/settings.rb +12 -25
  45. data/lib/lazier/string.rb +17 -38
  46. data/lib/lazier/timezone.rb +168 -164
  47. data/lib/lazier/version.rb +3 -4
  48. data/locales/en.yml +52 -51
  49. data/locales/it.yml +51 -50
  50. data/spec/coverage_helper.rb +0 -1
  51. data/spec/lazier/boolean_spec.rb +2 -3
  52. data/spec/lazier/configuration_spec.rb +3 -5
  53. data/spec/lazier/datetime_spec.rb +34 -95
  54. data/spec/lazier/exceptions_spec.rb +25 -0
  55. data/spec/lazier/hash_spec.rb +0 -21
  56. data/spec/lazier/i18n_spec.rb +135 -51
  57. data/spec/lazier/math_spec.rb +0 -1
  58. data/spec/lazier/object_spec.rb +105 -100
  59. data/spec/lazier/pathname_spec.rb +0 -1
  60. data/spec/lazier/settings_spec.rb +25 -28
  61. data/spec/lazier/string_spec.rb +7 -20
  62. data/spec/lazier/timezone_spec.rb +101 -87
  63. data/spec/lazier_spec.rb +25 -8
  64. data/spec/spec_helper.rb +3 -2
  65. metadata +15 -44
  66. data/doc/Lazier/Localizer.html +0 -545
  67. data/lib/lazier/localizer.rb +0 -41
  68. data/spec/lazier/localizer_spec.rb +0 -45
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -10,13 +9,13 @@ module Lazier
10
9
  # @see http://semver.org
11
10
  module Version
12
11
  # The major version.
13
- MAJOR = 3
12
+ MAJOR = 4
14
13
 
15
14
  # The minor version.
16
- MINOR = 5
15
+ MINOR = 0
17
16
 
18
17
  # The patch version.
19
- PATCH = 7
18
+ PATCH = 0
20
19
 
21
20
  # The current version of lazier.
22
21
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
@@ -5,54 +5,55 @@
5
5
  #
6
6
 
7
7
  ---
8
- lazier:
9
- boolean:
10
- - "Yes"
11
- - "No"
12
- date:
13
- long_months:
14
- - "January"
15
- - "February"
16
- - "March"
17
- - "April"
18
- - "May"
19
- - "June"
20
- - "July"
21
- - "August"
22
- - "September"
23
- - "October"
24
- - "November"
25
- - "December"
26
- short_months:
27
- - "Jan"
28
- - "Feb"
29
- - "Mar"
30
- - "Apr"
31
- - "May"
32
- - "Jun"
33
- - "Jul"
34
- - "Aug"
35
- - "Sep"
36
- - "Oct"
37
- - "Nov"
38
- - "Dec"
39
- long_days:
40
- - "Sunday"
41
- - "Monday"
42
- - "Tuesday"
43
- - "Wednesday"
44
- - "Thursday"
45
- - "Friday"
46
- - "Saturday"
47
- short_days:
48
- - "Sun"
49
- - "Mon"
50
- - "Tue"
51
- - "Wed"
52
- - "Thu"
53
- - "Fri"
54
- - "Sat"
55
- configuration:
56
- not_defined: "Property %1 is not defined for %2."
57
- required: "Property %1 is required for %2."
58
- readonly: "Property %1 is readonly for %2."
8
+ en:
9
+ lazier:
10
+ boolean:
11
+ - "Yes"
12
+ - "No"
13
+ date:
14
+ long_months:
15
+ - "January"
16
+ - "February"
17
+ - "March"
18
+ - "April"
19
+ - "May"
20
+ - "June"
21
+ - "July"
22
+ - "August"
23
+ - "September"
24
+ - "October"
25
+ - "November"
26
+ - "December"
27
+ short_months:
28
+ - "Jan"
29
+ - "Feb"
30
+ - "Mar"
31
+ - "Apr"
32
+ - "May"
33
+ - "Jun"
34
+ - "Jul"
35
+ - "Aug"
36
+ - "Sep"
37
+ - "Oct"
38
+ - "Nov"
39
+ - "Dec"
40
+ long_days:
41
+ - "Sunday"
42
+ - "Monday"
43
+ - "Tuesday"
44
+ - "Wednesday"
45
+ - "Thursday"
46
+ - "Friday"
47
+ - "Saturday"
48
+ short_days:
49
+ - "Sun"
50
+ - "Mon"
51
+ - "Tue"
52
+ - "Wed"
53
+ - "Thu"
54
+ - "Fri"
55
+ - "Sat"
56
+ configuration:
57
+ not_defined: "Property %{name} is not defined for %{class}."
58
+ required: "Property %{name} is required for %{class}."
59
+ readonly: "Property %{name} is readonly for %{class}."
@@ -5,53 +5,54 @@
5
5
  #
6
6
 
7
7
  ---
8
- lazier:
9
- boolean:
10
- - "Yes"
11
- - "No"
12
- date:
13
- long_months:
14
- - "Gennaio"
15
- - "Febbraio"
16
- - "Marzo"
17
- - "Aprile"
18
- - "Maggio"
19
- - "Giugno"
20
- - "Luglio"
21
- - "Agosto"
22
- - "Settembre"
23
- - "Ottobre"
24
- - "Novembre"
25
- - "Dicembre"
26
- short_monts:
27
- - "Gen"
28
- - "Feb"
29
- - "Mar"
30
- - "Apr"
31
- - "Mag"
32
- - "Giu"
33
- - "Lug"
34
- - "Ago"
35
- - "SetOtt"
36
- - "Nov"
37
- - "Dic"
38
- long_days:
39
- - "Domenica"
40
- - "Lunedì"
41
- - "Martedì"
42
- - "Mercoledì"
43
- - "Giovedì"
44
- - "Venerdì"
45
- - "Sabato"
46
- short_days:
47
- - "Dom"
48
- - "Lun"
49
- - "Mar"
50
- - "Mer"
51
- - "Gio"
52
- - "Ven"
53
- - "Sab"
54
- configuration:
55
- not_defined: "La proprietà %1 non è definita per %2."
56
- required: "La proprietà %1 è obbligatoria per %2."
57
- readonly: "La proprietà %1 è in sola lettura per %2."
8
+ it:
9
+ lazier:
10
+ boolean:
11
+ - ""
12
+ - "No"
13
+ date:
14
+ long_months:
15
+ - "Gennaio"
16
+ - "Febbraio"
17
+ - "Marzo"
18
+ - "Aprile"
19
+ - "Maggio"
20
+ - "Giugno"
21
+ - "Luglio"
22
+ - "Agosto"
23
+ - "Settembre"
24
+ - "Ottobre"
25
+ - "Novembre"
26
+ - "Dicembre"
27
+ short_months:
28
+ - "Gen"
29
+ - "Feb"
30
+ - "Mar"
31
+ - "Apr"
32
+ - "Mag"
33
+ - "Giu"
34
+ - "Lug"
35
+ - "Ago"
36
+ - "SetOtt"
37
+ - "Nov"
38
+ - "Dic"
39
+ long_days:
40
+ - "Domenica"
41
+ - "Lunedì"
42
+ - "Martedì"
43
+ - "Mercoledì"
44
+ - "Giovedì"
45
+ - "Venerdì"
46
+ - "Sabato"
47
+ short_days:
48
+ - "Dom"
49
+ - "Lun"
50
+ - "Mar"
51
+ - "Mer"
52
+ - "Gio"
53
+ - "Ven"
54
+ - "Sab"
55
+ configuration:
56
+ not_defined: "La proprietà %{name} non è definita per %{class}."
57
+ required: "La proprietà %{name} è obbligatoria per %{class}."
58
+ readonly: "La proprietà %{name} è in sola lettura per %{class}."
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -23,8 +22,8 @@ describe Lazier::Boolean do
23
22
 
24
23
  describe "#value" do
25
24
  it "should return self" do
26
- expect(true.value).to be_true
27
- expect(false.value).to be_false
25
+ expect(true.value).to be_truthy
26
+ expect(false.value).to be_falsey
28
27
  end
29
28
  end
30
29
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -23,12 +22,11 @@ describe Lazier::Configuration do
23
22
 
24
23
  it "should not allow writing readonly properties" do
25
24
  subject = ConfigurationSpecSample.new(required: 1)
26
-
27
- expect { subject .readonly = "4" }.to raise_error(ArgumentError)
28
- expect(subject .readonly).to eq("2")
25
+ expect { subject.readonly = "4" }.to raise_error(ArgumentError)
26
+ expect(subject.readonly).to eq("2")
29
27
  end
30
28
 
31
- it "should blow up for require properties" do
29
+ it "should blow up for required properties" do
32
30
  expect { ConfigurationSpecSample.new }.to raise_error(ArgumentError)
33
31
  end
34
32
  end
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  #
3
2
  # This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
4
3
  # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
@@ -8,13 +7,12 @@ require "spec_helper"
8
7
 
9
8
  describe Lazier::DateTime do
10
9
  let(:random_subject) { ::DateTime.civil(1990 + rand(30), 1 + rand(10), 1 + rand(25), 1 + rand(20), 1 + rand(58), 1 + rand(58)).in_time_zone }
11
- let(:fixed_subject){ ::DateTime.civil(2005, 6, 7, 8, 9, 10, ::DateTime.rationalize_offset(25200)) }
10
+ let(:fixed_subject){ ::DateTime.civil(2005, 6, 7, 8, 9, 10, ::ActiveSupport::TimeZone.rationalize_offset(25200)) }
12
11
  let(:subject_zone) { ::ActiveSupport::TimeZone["Mountain Time (US & Canada)"] }
13
12
  let(:zone_without_dst) { ::ActiveSupport::TimeZone["International Date Line West"] }
14
13
 
15
14
  before(:all) do
16
15
  Lazier.load!
17
- ::Lazier::Settings.instance.i18n = :en
18
16
  end
19
17
 
20
18
  describe ".days" do
@@ -24,7 +22,7 @@ describe Lazier::DateTime do
24
22
  expect(::DateTime.days(false)).to be_a(::Array)
25
23
  expect(::DateTime.days(false)[3]).to eq({value: "4", label: "Wednesday"})
26
24
 
27
- ::Lazier.settings.setup_date_names(nil, nil, 7.times.map {|i| (i + 1).to_s * 2}, 7.times.map {|i| (i + 1).to_s})
25
+ ::Lazier.settings.setup_date_names(long_days: 7.times.map {|i| (i + 1).to_s * 2}, short_days: 7.times.map {|i| (i + 1).to_s})
28
26
  expect(::DateTime.days).to be_a(::Array)
29
27
  expect(::DateTime.days[3]).to eq({value: "4", label: "4"})
30
28
  expect(::DateTime.days(false)).to be_a(::Array)
@@ -39,7 +37,7 @@ describe Lazier::DateTime do
39
37
  expect(::DateTime.months(false)).to be_a(::Array)
40
38
  expect(::DateTime.months(false)[6]).to eq({value: "07", label: "July"})
41
39
 
42
- ::Lazier.settings.setup_date_names(12.times.map {|i| (i + 1).to_s * 2}, 12.times.map {|i| (i + 1).to_s}, nil, nil)
40
+ ::Lazier.settings.setup_date_names(long_months: 12.times.map {|i| (i + 1).to_s * 2}, short_months: 12.times.map {|i| (i + 1).to_s})
43
41
  expect(::DateTime.months).to be_a(::Array)
44
42
  expect(::DateTime.months[6]).to eq({value: "07", label: "7"})
45
43
  expect(::DateTime.months(false)).to be_a(::Array)
@@ -50,59 +48,10 @@ describe Lazier::DateTime do
50
48
  describe ".years" do
51
49
  it "should return a range of years" do
52
50
  expect(::DateTime.years).to eq((::Date.today.year - 10..::Date.today.year + 10).to_a)
53
- expect(::DateTime.years(5)).to eq((::Date.today.year - 5..::Date.today.year + 5).to_a)
54
- expect(::DateTime.years(5, true, nil, true).map {|d| d[:value]}).to eq((::Date.today.year - 5..::Date.today.year + 5).to_a)
55
- expect(::DateTime.years(5, false)).to eq((::Date.today.year - 5..::Date.today.year).to_a)
56
- expect(::DateTime.years(5, false, 1900)).to eq((1895..1900).to_a)
57
- end
58
- end
59
-
60
- describe ".timezones" do
61
- it "should list all timezones" do
62
- expect(::DateTime.timezones).to eq(::ActiveSupport::TimeZone.all)
63
- end
64
- end
65
-
66
- describe ".list_timezones" do
67
- it "should forward to ActiveSupport::TimeZone" do
68
- expect(::ActiveSupport::TimeZone).to receive(:list_all)
69
- ::DateTime.list_timezones
70
- end
71
- end
72
-
73
- describe ".find_timezone" do
74
- it "should forward to ActiveSupport::TimeZone" do
75
- expect(::ActiveSupport::TimeZone).to receive(:find)
76
- ::DateTime.find_timezone(subject_zone.name)
77
- end
78
- end
79
-
80
- describe ".rationalize_offset" do
81
- it "should return the correct rational value" do
82
- expect(::ActiveSupport::TimeZone).to receive(:rationalize_offset)
83
- ::DateTime.rationalize_offset(0)
84
- end
85
- end
86
-
87
- describe ".parameterize_zone" do
88
- it "should forward to ActiveSupport::TimeZone" do
89
- expect(::ActiveSupport::TimeZone).to receive(:parameterize_zone)
90
- ::DateTime.parameterize_zone(subject_zone)
91
- end
92
- end
93
-
94
- describe ".unparameterize_zone" do
95
- it "should forward to ActiveSupport::TimeZone" do
96
- expect(::ActiveSupport::TimeZone).to receive(:unparameterize_zone)
97
- ::DateTime.unparameterize_zone(subject_zone)
98
- end
99
- end
100
-
101
- describe ".easter" do
102
- it "should compute the valid Easter day" do
103
- {1984 => "0422", 1995 => "0416", 2006 => "0416", 2017 => "0416"}.each do |year, date|
104
- expect(::DateTime.easter(year).strftime("%Y%m%d")).to eq("#{year}#{date}")
105
- end
51
+ expect(::DateTime.years(offset: 5)).to eq((::Date.today.year - 5..::Date.today.year + 5).to_a)
52
+ expect(::DateTime.years(as_objects: true).map {|d| d[:value]}).to eq((::Date.today.year - 10..::Date.today.year + 10).to_a)
53
+ expect(::DateTime.years(also_future: false)).to eq((::Date.today.year - 10..::Date.today.year).to_a)
54
+ expect(::DateTime.years(reference: 1900)).to eq((1890..1910).to_a)
106
55
  end
107
56
  end
108
57
 
@@ -122,28 +71,30 @@ describe Lazier::DateTime do
122
71
  end
123
72
  end
124
73
 
125
- describe ".is_valid?" do
74
+ describe ".valid?" do
126
75
  it "should recognize a valid date" do
127
- expect(::DateTime.is_valid?("2012-04-05", "%F")).to be_true
128
- expect(::DateTime.is_valid?("2012-04-05", :ct_date)).to be_true
76
+ expect(::DateTime.valid?("2012-04-05", "%F")).to be_truthy
77
+ expect(::DateTime.valid?("2012-04-05", :ct_date)).to be_truthy
129
78
  end
130
79
 
131
80
  it "should fail if the argument or the format is not valid" do
132
- expect(::DateTime.is_valid?("ABC", "%F")).to be_false
133
- expect(::DateTime.is_valid?("2012-04-05", "%X")).to be_false
81
+ expect(::DateTime.valid?("ABC", "%F")).to be_falsey
82
+ expect(::DateTime.valid?("2012-04-05", "%X")).to be_falsey
134
83
  end
135
84
  end
136
85
 
137
- describe "#utc_time" do
138
- it "should convert to UTC Time" do
139
- expect(random_subject.utc_time).to be_a(::Time)
86
+ describe ".easter" do
87
+ it "should compute the valid Easter day" do
88
+ {1984 => "0422", 1995 => "0416", 2006 => "0416", 2017 => "0416"}.each do |year, date|
89
+ expect(::DateTime.easter(year).strftime("%Y%m%d")).to eq("#{year}#{date}")
90
+ end
140
91
  end
141
92
  end
142
93
 
143
- describe "#in_months" do
94
+ describe "#months_since_year" do
144
95
  it "should return the amount of months passed since the start of the subject year" do
145
- expect(::Date.today.in_months).to eq(::Date.today.month)
146
- expect(fixed_subject.in_months(2000)).to eq(66)
96
+ expect(::Date.today.months_since_year).to eq(::Date.today.month)
97
+ expect(fixed_subject.months_since_year(2000)).to eq(66)
147
98
  end
148
99
  end
149
100
 
@@ -154,46 +105,34 @@ describe Lazier::DateTime do
154
105
  end
155
106
  end
156
107
 
157
- describe "#lstrftime" do
108
+ describe "#format" do
158
109
  it "should return corrected formatted string" do
159
- expect(fixed_subject.lstrftime(:db)).to eq("db")
160
- expect(fixed_subject.lstrftime("%F")).to eq("2005-06-07")
161
- expect(fixed_subject.lstrftime(:ct_iso_8601)).to eq("2005-06-07T08:09:10+0700")
110
+ expect(fixed_subject.format(:db)).to eq("db")
111
+ expect(fixed_subject.format("%F")).to eq("2005-06-07")
112
+ expect(fixed_subject.format(:ct_iso_8601)).to eq("2005-06-07T08:09:10+0700")
162
113
 
163
114
  ::Lazier.settings.setup_date_names
164
115
  ::Lazier.settings.setup_date_formats({ct_local_test: "%a %A %b %B %d %Y %H"})
165
- expect(fixed_subject.lstrftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 08")
116
+ expect(fixed_subject.format(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 08")
166
117
 
167
118
  ::Lazier.settings.setup_date_names(
168
- 12.times.map {|i| (i + 1).to_s * 2}, 12.times.map {|i| (i + 1).to_s},
169
- 7.times.map {|i| (i + 1).to_s * 2}, 7.times.map {|i| (i + 1).to_s}
119
+ long_months: 12.times.map {|i| (i + 1).to_s * 2}, short_months: 12.times.map {|i| (i + 1).to_s},
120
+ long_days: 7.times.map {|i| (i + 1).to_s * 2}, short_days: 7.times.map {|i| (i + 1).to_s}
170
121
  )
171
122
 
172
- expect(fixed_subject.lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 08")
123
+ expect(fixed_subject.format(:ct_local_test)).to eq("3 33 6 66 07 2005 08")
173
124
  end
174
- end
175
125
 
176
- describe "#local_strftime" do
177
- it "should retrieve the date in the current timezone" do
178
- ::Time.zone = ::ActiveSupport::TimeZone[0]
179
- ::Lazier.settings.setup_date_formats({ct_local_test: "%a %A %b %B %d %Y %H"})
180
- expect(fixed_subject.local_strftime(:ct_local_test)).to eq("Tue Tuesday Jun June 07 2005 01")
126
+ it "should ignore custom formats if requested to" do
127
+ expect(fixed_subject.format(:ct_iso_8601, custom: false)).to eq("ct_iso_8601")
181
128
  end
182
- end
183
129
 
184
- describe "#local_lstrftime" do
185
- it "should retrieve the date in the current timezone" do
130
+ it "should move in the current time zone if request to" do
131
+ original_zone = ::Time.zone
186
132
  ::Time.zone = ::ActiveSupport::TimeZone[0]
187
133
 
188
- ::Lazier.settings.setup_date_names
189
- ::Lazier.settings.setup_date_formats({ct_local_test: "%a %A %b %B %d %Y %H"})
190
-
191
- ::Lazier.settings.setup_date_names(
192
- 12.times.map {|i| (i + 1).to_s * 2}, 12.times.map {|i| (i + 1).to_s},
193
- 7.times.map {|i| (i + 1).to_s * 2}, 7.times.map {|i| (i + 1).to_s}
194
- )
195
-
196
- expect(fixed_subject.local_lstrftime(:ct_local_test)).to eq("3 33 6 66 07 2005 01")
134
+ expect(fixed_subject.format(:ct_iso_8601, change_time_zone: true)).to eq("2005-06-07T01:09:10+0000")
135
+ ::Time.zone = original_zone
197
136
  end
198
137
  end
199
138
  end