lazier 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.travis-gemfile +2 -2
  3. data/CHANGELOG.md +4 -0
  4. data/Gemfile +6 -6
  5. data/README.md +1 -1
  6. data/doc/Lazier.html +185 -70
  7. data/doc/Lazier/Boolean.html +5 -5
  8. data/doc/Lazier/Configuration.html +78 -16
  9. data/doc/Lazier/DateTime.html +13 -12
  10. data/doc/Lazier/DateTime/ClassMethods.html +6 -6
  11. data/doc/Lazier/Exceptions.html +3 -3
  12. data/doc/Lazier/Exceptions/Debug.html +3 -3
  13. data/doc/Lazier/Exceptions/MissingTranslation.html +9 -9
  14. data/doc/Lazier/Exceptions/TranslationExceptionHandler.html +73 -9
  15. data/doc/Lazier/Hash.html +7 -7
  16. data/doc/Lazier/I18n.html +41 -41
  17. data/doc/Lazier/Math.html +4 -4
  18. data/doc/Lazier/Math/ClassMethods.html +7 -7
  19. data/doc/Lazier/Object.html +29 -26
  20. data/doc/Lazier/Pathname.html +11 -12
  21. data/doc/Lazier/Settings.html +63 -63
  22. data/doc/Lazier/String.html +122 -21
  23. data/doc/Lazier/TimeZone.html +128 -32
  24. data/doc/Lazier/TimeZone/ClassMethods.html +5 -5
  25. data/doc/Lazier/Version.html +4 -4
  26. data/doc/_index.html +4 -4
  27. data/doc/class_list.html +5 -1
  28. data/doc/file.README.html +4 -4
  29. data/doc/file_list.html +5 -1
  30. data/doc/frames.html +1 -1
  31. data/doc/index.html +4 -4
  32. data/doc/js/full_list.js +4 -1
  33. data/doc/method_list.html +91 -81
  34. data/doc/top-level-namespace.html +3 -3
  35. data/lib/lazier.rb +18 -17
  36. data/lib/lazier/boolean.rb +1 -1
  37. data/lib/lazier/configuration.rb +6 -6
  38. data/lib/lazier/datetime.rb +11 -11
  39. data/lib/lazier/exceptions.rb +7 -2
  40. data/lib/lazier/hash.rb +4 -4
  41. data/lib/lazier/i18n.rb +7 -7
  42. data/lib/lazier/math.rb +3 -3
  43. data/lib/lazier/object.rb +17 -15
  44. data/lib/lazier/pathname.rb +3 -5
  45. data/lib/lazier/settings.rb +10 -10
  46. data/lib/lazier/string.rb +10 -1
  47. data/lib/lazier/timezone.rb +23 -25
  48. data/lib/lazier/version.rb +1 -1
  49. data/spec/lazier/string_spec.rb +14 -0
  50. data/spec/spec_helper.rb +1 -8
  51. metadata +2 -2
@@ -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.
@@ -4,7 +4,7 @@
4
4
  #
5
5
 
6
6
  module Lazier
7
- # Extensions for timezone objects.
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] If to put the colon in the output string.
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] If to include offset into the representation.
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] If to return the offset as a Rational.
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] If to return the name with DST indication.
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] If to return the offset as a Rational.
202
- # @param dst [Boolean] If to return the offset when the DST is active.
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] If to return the offset as a Rational.
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] If to represent with (DST) active.
255
+ # @param dst [Boolean] Whether to represent with (DST) active.
256
256
  # @param args [Hash] Parameters for the formatting:
257
- #
258
- # * **label** (`String`): The label to use. Default to the current alias.
259
- # * **dst_label** (`String`): Label for the DST indication. Defaults to ` (DST)`.
260
- # * **utc_label** (`String`): Label for the UTC name. Defaults to `GMT`. *Only used when `parameterized` is `false`.
261
- # * **year** (`Fixnum`): The year to which refer to. Defaults to the current year.
262
- # * **parameterized** (`Boolean`): If to represent as parameterized.
263
- # * **with_offset** (`Boolean`): If to include offset into the representation. *Only used when `parameterized` is `true`.
264
- # * **offset_position** (`Symbol`): Where to put the offset. Valid values are `:begin` or `:end`. *Only used when `parameterized` is `false`.
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.
@@ -12,7 +12,7 @@ module Lazier
12
12
  MAJOR = 4
13
13
 
14
14
  # The minor version.
15
- MINOR = 1
15
+ MINOR = 2
16
16
 
17
17
  # The patch version.
18
18
  PATCH = 0
@@ -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)
@@ -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.1.0
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-10-02 00:00:00.000000000 Z
11
+ date: 2014-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport