lazier 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis-gemfile +2 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +6 -6
- data/README.md +1 -1
- data/doc/Lazier.html +185 -70
- data/doc/Lazier/Boolean.html +5 -5
- data/doc/Lazier/Configuration.html +78 -16
- data/doc/Lazier/DateTime.html +13 -12
- data/doc/Lazier/DateTime/ClassMethods.html +6 -6
- data/doc/Lazier/Exceptions.html +3 -3
- data/doc/Lazier/Exceptions/Debug.html +3 -3
- data/doc/Lazier/Exceptions/MissingTranslation.html +9 -9
- data/doc/Lazier/Exceptions/TranslationExceptionHandler.html +73 -9
- data/doc/Lazier/Hash.html +7 -7
- data/doc/Lazier/I18n.html +41 -41
- data/doc/Lazier/Math.html +4 -4
- data/doc/Lazier/Math/ClassMethods.html +7 -7
- data/doc/Lazier/Object.html +29 -26
- data/doc/Lazier/Pathname.html +11 -12
- data/doc/Lazier/Settings.html +63 -63
- data/doc/Lazier/String.html +122 -21
- data/doc/Lazier/TimeZone.html +128 -32
- data/doc/Lazier/TimeZone/ClassMethods.html +5 -5
- data/doc/Lazier/Version.html +4 -4
- data/doc/_index.html +4 -4
- data/doc/class_list.html +5 -1
- data/doc/file.README.html +4 -4
- data/doc/file_list.html +5 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +4 -4
- data/doc/js/full_list.js +4 -1
- data/doc/method_list.html +91 -81
- data/doc/top-level-namespace.html +3 -3
- data/lib/lazier.rb +18 -17
- data/lib/lazier/boolean.rb +1 -1
- data/lib/lazier/configuration.rb +6 -6
- data/lib/lazier/datetime.rb +11 -11
- data/lib/lazier/exceptions.rb +7 -2
- data/lib/lazier/hash.rb +4 -4
- data/lib/lazier/i18n.rb +7 -7
- data/lib/lazier/math.rb +3 -3
- data/lib/lazier/object.rb +17 -15
- data/lib/lazier/pathname.rb +3 -5
- data/lib/lazier/settings.rb +10 -10
- data/lib/lazier/string.rb +10 -1
- data/lib/lazier/timezone.rb +23 -25
- data/lib/lazier/version.rb +1 -1
- data/spec/lazier/string_spec.rb +14 -0
- data/spec/spec_helper.rb +1 -8
- metadata +2 -2
data/lib/lazier/string.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
module Lazier
|
7
|
-
# Extensions for the String class.
|
7
|
+
# Extensions for the `String` class.
|
8
8
|
module String
|
9
9
|
extend ::ActiveSupport::Concern
|
10
10
|
|
@@ -17,6 +17,15 @@ module Lazier
|
|
17
17
|
encode("utf-16", invalid: :replace, undef: :replace, replace: replacement).encode("utf-8")
|
18
18
|
end
|
19
19
|
|
20
|
+
# Makes sure the string starts with the scheme for the specified protocol.
|
21
|
+
#
|
22
|
+
# @param protocol [String] The protocol for the URL.
|
23
|
+
# @param secure [Boolean] If the scheme should be secure or not.
|
24
|
+
def ensure_url_with_scheme(protocol = "http", secure: false)
|
25
|
+
schema = protocol + (secure ? "s" : "")
|
26
|
+
self !~ /^(#{protocol}(s?):\/\/)/ ? "#{schema}://#{self}" : self
|
27
|
+
end
|
28
|
+
|
20
29
|
# Returns the string itself for use in form helpers.
|
21
30
|
#
|
22
31
|
# @return [String] The string itself.
|
data/lib/lazier/timezone.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
module Lazier
|
7
|
-
# Extensions for
|
7
|
+
# Extensions for `TimeZone` objects.
|
8
8
|
module TimeZone
|
9
9
|
extend ::ActiveSupport::Concern
|
10
10
|
|
@@ -34,7 +34,7 @@ module Lazier
|
|
34
34
|
# Returns a +HH:MM formatted representation of the offset.
|
35
35
|
#
|
36
36
|
# @param offset [Rational|Fixnum] The offset to represent, in seconds or as a rational.
|
37
|
-
# @param colon [Boolean]
|
37
|
+
# @param colon [Boolean] Whether to put the colon in the output string.
|
38
38
|
# @return [String] The formatted offset.
|
39
39
|
def format_offset(offset, colon = true)
|
40
40
|
seconds_to_utc_offset(offset.is_a?(::Rational) ? (offset * 86_400).to_i : offset, colon)
|
@@ -78,7 +78,7 @@ module Lazier
|
|
78
78
|
# # => "-0800@pacific-time-us-canada"
|
79
79
|
# ```
|
80
80
|
# @param tz [TimeZone|String] The zone to represent.
|
81
|
-
# @param with_offset [Boolean]
|
81
|
+
# @param with_offset [Boolean] Whether to include offset into the representation.
|
82
82
|
# @return [String] A string representation which can be used for searches.
|
83
83
|
def parameterize(tz, with_offset = true)
|
84
84
|
tz = tz.to_str unless tz.is_a?(::String)
|
@@ -147,7 +147,7 @@ module Lazier
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
|
-
# Returns a list of valid aliases (city names) for this timezone (basing on offset).
|
150
|
+
# Returns a list of valid aliases (city names) for this timezone (basing on the offset).
|
151
151
|
# @return [Array] A list of aliases for this timezone
|
152
152
|
def aliases
|
153
153
|
reference = self.class::MAPPING.fetch(name, name).gsub("_", " ")
|
@@ -156,8 +156,8 @@ module Lazier
|
|
156
156
|
|
157
157
|
# Returns the current offset for this timezone, taking care of Daylight Saving Time (DST).
|
158
158
|
#
|
159
|
-
# @param rational [Boolean]
|
160
|
-
# @param date [DateTime] The date to consider. Defaults to now.
|
159
|
+
# @param rational [Boolean] Whether to return the offset as a Rational.
|
160
|
+
# @param date [DateTime|NilClass] The date to consider. Defaults to now.
|
161
161
|
# @return [Fixnum|Rational] The offset of this timezone.
|
162
162
|
def current_offset(rational = false, date = nil)
|
163
163
|
date = (date || ::DateTime.current).in_time_zone
|
@@ -185,7 +185,7 @@ module Lazier
|
|
185
185
|
|
186
186
|
# Returns the current name.
|
187
187
|
#
|
188
|
-
# @param dst [Boolean]
|
188
|
+
# @param dst [Boolean] Whether to return the name with DST indication.
|
189
189
|
# @param dst_label [String] Label for the DST indication. Defaults to ` (DST)`.
|
190
190
|
# @param year [Fixnum] The year to which refer to. Defaults to the current year. *Only required when `dst` is true*.
|
191
191
|
# @return [String] The name for the zone.
|
@@ -198,9 +198,9 @@ module Lazier
|
|
198
198
|
|
199
199
|
# Returns the standard offset for this timezone.
|
200
200
|
#
|
201
|
-
# @param rational [Boolean]
|
202
|
-
# @param dst [Boolean]
|
203
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
201
|
+
# @param rational [Boolean] Whether to return he offset as a `Rational`.
|
202
|
+
# @param dst [Boolean] Whether to return the offset when the DST is active.
|
203
|
+
# @param year [Fixnum|NilClass] The year to which refer to. Defaults to the current year.
|
204
204
|
# @return [Fixnum|Rational] The offset of this timezone.
|
205
205
|
def offset(rational: false, dst: false, year: nil)
|
206
206
|
rv =
|
@@ -216,7 +216,7 @@ module Lazier
|
|
216
216
|
|
217
217
|
# Checks if the timezone uses Daylight Saving Time (DST) for that date or year.
|
218
218
|
#
|
219
|
-
# @param reference [Date|DateTime] The date or year to check. Defaults to the current year.
|
219
|
+
# @param reference [Date|DateTime|NilClass] The date or year to check. Defaults to the current year.
|
220
220
|
# @return [Boolean] `true` if the zone uses DST for that date or year, `false` otherwise.
|
221
221
|
def uses_dst?(reference = nil)
|
222
222
|
if reference.is_a?(Date) || reference.is_a?(DateTime) || reference.is_a?(Time)
|
@@ -228,7 +228,7 @@ module Lazier
|
|
228
228
|
|
229
229
|
# Gets a period for this timezone when the Daylight Saving Time (DST) is active (it takes care of different hemispheres).
|
230
230
|
#
|
231
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
231
|
+
# @param year [Fixnum|NilClass] The year to which refer to. Defaults to the current year.
|
232
232
|
# @return [TimezonePeriod] A period when the Daylight Saving Time (DST) is active or `nil` if the timezone doesn't use DST for that year.
|
233
233
|
def dst_period(year = nil)
|
234
234
|
year ||= ::Date.current.year
|
@@ -242,8 +242,8 @@ module Lazier
|
|
242
242
|
|
243
243
|
# Return the correction applied to the standard offset the timezone when the Daylight Saving Time (DST) is active.
|
244
244
|
#
|
245
|
-
# @param rational [Boolean]
|
246
|
-
# @param year [Fixnum] The year to which refer to. Defaults to the current year.
|
245
|
+
# @param rational [Boolean] Whether to return the offset as a Rational.
|
246
|
+
# @param year [Fixnum|NilClass] The year to which refer to. Defaults to the current year.
|
247
247
|
# @return [Fixnum|Rational] The correction for dst.
|
248
248
|
def dst_correction(rational = false, year = nil)
|
249
249
|
rv = dst_offset(year, :std_offset)
|
@@ -252,18 +252,16 @@ module Lazier
|
|
252
252
|
|
253
253
|
# Formats this zone as a string.
|
254
254
|
#
|
255
|
-
# @param dst [Boolean]
|
255
|
+
# @param dst [Boolean] Whether to represent with (DST) active.
|
256
256
|
# @param args [Hash] Parameters for the formatting:
|
257
|
-
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
262
|
-
#
|
263
|
-
#
|
264
|
-
#
|
265
|
-
# * **colon** (`Boolean`): If include a colon in the offset. *Only used when `parameterized` is `false`.
|
266
|
-
#
|
257
|
+
# @option args label [String]: The label to use. Default to the current alias.
|
258
|
+
# @option args dst_label [String]: Label for the DST indication. Defaults to ` (DST)`.
|
259
|
+
# @option args utc_label [String]: Label for the UTC name. Defaults to `GMT`. *Only used when `parameterized` is `false`.
|
260
|
+
# @option args year [Fixnum]: The year to which refer to. Defaults to the current year.
|
261
|
+
# @option args parameterized [Boolean]: Whether to represent as parameterized.
|
262
|
+
# @option args with_offset [Boolean]: Whether to include offset into the representation. *Only used when `parameterized` is `true`.
|
263
|
+
# @option args offset_position [Symbol]: Where to put the offset. Valid values are `:begin` or `:end`. *Only used when `parameterized` is `false`.
|
264
|
+
# @option args colon [Boolean]: If include a colon in the offset. *Only used when `parameterized` is `false`.
|
267
265
|
# @return [String] The string representation for this zone.
|
268
266
|
def to_str(dst = false, **args)
|
269
267
|
# PI: Ignore reek on this.
|
data/lib/lazier/version.rb
CHANGED
data/spec/lazier/string_spec.rb
CHANGED
@@ -29,6 +29,20 @@ describe Lazier::String do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
describe "#ensure_url_with_scheme" do
|
33
|
+
it "should return a URL with scheme" do
|
34
|
+
expect("http://google.com".ensure_url_with_scheme).to eq("http://google.com")
|
35
|
+
expect("http://google.com".ensure_url_with_scheme(secure: true)).to eq("http://google.com")
|
36
|
+
expect("google.com".ensure_url_with_scheme).to eq("http://google.com")
|
37
|
+
expect("google.com".ensure_url_with_scheme(secure: true)).to eq("https://google.com")
|
38
|
+
|
39
|
+
expect("http://google.com".ensure_url_with_scheme("ftp")).to eq("ftp://http://google.com")
|
40
|
+
expect("ftp://google.com".ensure_url_with_scheme("ftp", secure: true)).to eq("ftp://google.com")
|
41
|
+
expect("google.com".ensure_url_with_scheme("ftp")).to eq("ftp://google.com")
|
42
|
+
expect("google.com".ensure_url_with_scheme("ftp", secure: true)).to eq("ftps://google.com")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
32
46
|
describe "#value" do
|
33
47
|
it "should return the string itself" do
|
34
48
|
expect(subject.value).to eq(subject)
|
data/spec/spec_helper.rb
CHANGED
@@ -3,15 +3,8 @@
|
|
3
3
|
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
4
|
#
|
5
5
|
|
6
|
-
require "rubygems"
|
7
6
|
require "bundler/setup"
|
8
7
|
require File.dirname(__FILE__) + "/../lib/lazier"
|
9
8
|
|
10
|
-
RSpec.configure do |config|
|
11
|
-
config.expect_with :rspec do |c|
|
12
|
-
c.syntax = :expect
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
9
|
::I18n.enforce_available_locales = false
|
17
|
-
Lazier::I18n.default_locale = :en
|
10
|
+
Lazier::I18n.default_locale = :en
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shogun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|