lazier 4.2.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -8
- data/.rubocop.yml +48 -3
- data/.travis.yml +5 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +9 -8
- data/README.md +0 -1
- data/Rakefile +20 -4
- data/doc/Lazier.html +214 -3
- data/doc/Lazier/Boolean.html +2 -2
- data/doc/Lazier/Configuration.html +3 -3
- data/doc/Lazier/DateTime.html +16 -16
- data/doc/Lazier/DateTime/ClassMethods.html +6 -6
- data/doc/Lazier/Exceptions.html +2 -2
- data/doc/Lazier/Exceptions/Debug.html +2 -2
- data/doc/Lazier/Exceptions/MissingTranslation.html +2 -2
- data/doc/Lazier/Exceptions/TranslationExceptionHandler.html +2 -2
- data/doc/Lazier/Hash.html +3 -3
- data/doc/Lazier/I18n.html +11 -11
- data/doc/Lazier/Math.html +2 -2
- data/doc/Lazier/Math/ClassMethods.html +2 -2
- data/doc/Lazier/Object.html +16 -22
- data/doc/Lazier/Pathname.html +2 -2
- data/doc/Lazier/Settings.html +2 -2
- data/doc/Lazier/String.html +2 -2
- data/doc/Lazier/TimeZone.html +42 -42
- data/doc/Lazier/TimeZone/ClassMethods.html +2 -2
- data/doc/Lazier/Version.html +3 -3
- data/doc/_index.html +6 -6
- data/doc/file.README.html +3 -4
- data/doc/index.html +3 -4
- data/doc/method_list.html +106 -88
- data/doc/top-level-namespace.html +2 -2
- data/lazier.gemspec +2 -2
- data/lib/lazier.rb +0 -2
- data/lib/lazier/configuration.rb +1 -1
- data/lib/lazier/datetime.rb +10 -5
- data/lib/lazier/hash.rb +1 -1
- data/lib/lazier/i18n.rb +2 -2
- data/lib/lazier/object.rb +18 -10
- data/lib/lazier/timezone.rb +8 -8
- data/lib/lazier/version.rb +1 -1
- data/spec/spec_helper.rb +17 -0
- metadata +6 -8
- data/spec/coverage_helper.rb +0 -19
@@ -103,9 +103,9 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Tue Mar 29 11:11:36 2016 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
|
-
0.8.7.6 (ruby-2.
|
108
|
+
0.8.7.6 (ruby-2.3.0).
|
109
109
|
</div>
|
110
110
|
|
111
111
|
</body>
|
data/lazier.gemspec
CHANGED
@@ -23,13 +23,13 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
24
24
|
gem.require_paths = ["lib"]
|
25
25
|
|
26
|
-
gem.required_ruby_version = ">= 2.
|
26
|
+
gem.required_ruby_version = ">= 2.3.0"
|
27
27
|
|
28
28
|
gem.add_dependency("activesupport", "~> 4.1")
|
29
29
|
gem.add_dependency("hashie", "~> 3.3")
|
30
30
|
|
31
31
|
if RUBY_ENGINE != "jruby"
|
32
|
-
gem.add_dependency("oj", "~> 2.
|
32
|
+
gem.add_dependency("oj", "~> 2.15")
|
33
33
|
else
|
34
34
|
gem.add_dependency("json", "~> 1.8")
|
35
35
|
end
|
data/lib/lazier.rb
CHANGED
data/lib/lazier/configuration.rb
CHANGED
@@ -21,7 +21,7 @@ module Lazier
|
|
21
21
|
# @param name [String|Symbol] The new property name.
|
22
22
|
# @param options [Hash] The options for the property.
|
23
23
|
# @option options [Boolean] :default Specify a default value for this property.
|
24
|
-
# @option options [Boolean] :required
|
24
|
+
# @option options [Boolean] :required Set the value as required for this property, this will raise an error if the value is unset when creating or editing.
|
25
25
|
# @option options [Boolean] :readonly Specify if the property is readonly, which means that it can only defined during creation of the configuration.
|
26
26
|
def self.property(name, options = {})
|
27
27
|
super(name, options)
|
data/lib/lazier/datetime.rb
CHANGED
@@ -16,9 +16,9 @@ module Lazier
|
|
16
16
|
# @param short [Boolean] If return the abbreviated representations.
|
17
17
|
# @return [Array] Return string representations of days.
|
18
18
|
def days(short = true)
|
19
|
-
::Lazier.settings.date_names[short ? :short_days : :long_days].map.with_index
|
19
|
+
::Lazier.settings.date_names[short ? :short_days : :long_days].map.with_index do |label, index|
|
20
20
|
{value: (index + 1).to_s, label: label}
|
21
|
-
|
21
|
+
end
|
22
22
|
end
|
23
23
|
|
24
24
|
# Returns strings representations of months.
|
@@ -27,9 +27,9 @@ module Lazier
|
|
27
27
|
# @param short [Boolean] If return the abbreviated representations.
|
28
28
|
# @return [Array] Return string representations of months.
|
29
29
|
def months(short = true)
|
30
|
-
::Lazier.settings.date_names[short ? :short_months : :long_months].map.with_index
|
30
|
+
::Lazier.settings.date_names[short ? :short_months : :long_months].map.with_index do |label, index|
|
31
31
|
{value: (index + 1).to_s.rjust(2, "0"), label: label}
|
32
|
-
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
35
|
# Returns a range of years.
|
@@ -107,13 +107,18 @@ module Lazier
|
|
107
107
|
_, b, c = data
|
108
108
|
|
109
109
|
[
|
110
|
-
|
110
|
+
easter_divide_first(b),
|
111
111
|
b % 4,
|
112
112
|
(c / 4.0).floor,
|
113
113
|
c % 4
|
114
114
|
]
|
115
115
|
end
|
116
116
|
|
117
|
+
# :nodoc:
|
118
|
+
def easter_divide_first(b)
|
119
|
+
b - (b / 4.0).floor - ((b - ((b + 8) / 25.0).floor + 1) / 3.0).floor
|
120
|
+
end
|
121
|
+
|
117
122
|
# :nodoc:
|
118
123
|
def easter_aggregate(year, data)
|
119
124
|
a = year % 19
|
data/lib/lazier/hash.rb
CHANGED
data/lib/lazier/i18n.rb
CHANGED
@@ -89,7 +89,7 @@ module Lazier
|
|
89
89
|
message = "#{root}.#{message}" if message !~ /^(\.|::)/
|
90
90
|
|
91
91
|
begin
|
92
|
-
::I18n.translate(message, **
|
92
|
+
::I18n.translate(message, **args.merge(raise: true))
|
93
93
|
rescue ::I18n::MissingTranslationData
|
94
94
|
raise Lazier::Exceptions::MissingTranslation, [locale, message]
|
95
95
|
end
|
@@ -124,7 +124,7 @@ module Lazier
|
|
124
124
|
private
|
125
125
|
|
126
126
|
# :nodoc:
|
127
|
-
OSX_DETECTION = "defaults read .GlobalPreferences AppleLanguages | awk 'NR==2{gsub(/[ ,]/, \"\");print}'"
|
127
|
+
OSX_DETECTION = "defaults read .GlobalPreferences AppleLanguages | awk 'NR==2{gsub(/[ ,]/, \"\");print}'".freeze
|
128
128
|
|
129
129
|
# :nodoc:
|
130
130
|
def system_locale
|
data/lib/lazier/object.rb
CHANGED
@@ -191,15 +191,12 @@ module Lazier
|
|
191
191
|
# @return [String|NilClass] The string representation of the object or `nil`, if the object is not a number.
|
192
192
|
def format_number(precision: nil, decimal_separator: nil, add_string: nil, k_separator: nil)
|
193
193
|
if number?
|
194
|
-
|
195
|
-
add_string ||= settings[:add_string]
|
194
|
+
precision, decimal_separator, add_string, k_separator = format_number_sanitize(precision, decimal_separator, add_string, k_separator)
|
196
195
|
|
197
|
-
rv = format("%0.#{
|
198
|
-
rv[0].gsub!(/(\d)(?=(\d{3})+(?!\d))/, "\\1#{k_separator
|
199
|
-
rv = rv.join(decimal_separator
|
196
|
+
rv = format("%0.#{precision}f", to_float).split(".")
|
197
|
+
rv[0].gsub!(/(\d)(?=(\d{3})+(?!\d))/, "\\1#{k_separator}")
|
198
|
+
rv = rv.join(decimal_separator)
|
200
199
|
add_string ? rv + " #{add_string}" : rv
|
201
|
-
else
|
202
|
-
nil
|
203
200
|
end
|
204
201
|
end
|
205
202
|
|
@@ -238,7 +235,7 @@ module Lazier
|
|
238
235
|
|
239
236
|
# :nodoc:
|
240
237
|
def convert_to_hash(value)
|
241
|
-
if
|
238
|
+
if is_a?(::Hash)
|
242
239
|
self
|
243
240
|
elsif value.is_a?(::Hash)
|
244
241
|
value
|
@@ -252,10 +249,21 @@ module Lazier
|
|
252
249
|
def sanitize_hash(hash, sanitizer, block)
|
253
250
|
operator = block ? block : ->(v) { v.send(sanitizer) }
|
254
251
|
|
255
|
-
hash.reduce(hash.class.new)
|
252
|
+
hash.reduce(hash.class.new) do |h, (k, v)|
|
256
253
|
h[k] = operator.call(v)
|
257
254
|
h
|
258
|
-
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
# :nodoc:
|
259
|
+
def format_number_sanitize(precision, decimal_separator, add_string, k_separator)
|
260
|
+
settings = ::Lazier.settings.format_number
|
261
|
+
precision = [precision || settings[:precision], 0].max
|
262
|
+
decimal_separator ||= settings[:decimal_separator]
|
263
|
+
add_string ||= settings[:add_string]
|
264
|
+
k_separator ||= settings[:k_separator]
|
265
|
+
|
266
|
+
[precision, decimal_separator, add_string, k_separator]
|
259
267
|
end
|
260
268
|
end
|
261
269
|
end
|
data/lib/lazier/timezone.rb
CHANGED
@@ -119,12 +119,14 @@ module Lazier
|
|
119
119
|
|
120
120
|
# :nodoc:
|
121
121
|
def fetch_aliases(zone, dst_label = "(DST)", parameterized = false)
|
122
|
-
zone.aliases.map
|
122
|
+
rv = zone.aliases.map do |zone_alias|
|
123
123
|
[
|
124
124
|
zone.to_str(false, label: zone_alias, parameterized: parameterized),
|
125
125
|
(zone.uses_dst? && dst_label) ? zone.to_str(true, label: zone_alias, dst_label: dst_label, parameterized: parameterized) : nil
|
126
126
|
]
|
127
|
-
|
127
|
+
end
|
128
|
+
|
129
|
+
rv.flatten.uniq.compact
|
128
130
|
end
|
129
131
|
|
130
132
|
# :nodoc:
|
@@ -136,12 +138,12 @@ module Lazier
|
|
136
138
|
|
137
139
|
# :nodoc:
|
138
140
|
def finalize_list_as_hash(all, dst_label, parameterized, sort_by_name)
|
139
|
-
rv = all.reduce({})
|
140
|
-
accu.merge(fetch_aliases(zone, dst_label, parameterized).reduce({})
|
141
|
+
rv = all.reduce({}) do |accu, zone|
|
142
|
+
accu.merge(fetch_aliases(zone, dst_label, parameterized).reduce({}) do |a, e|
|
141
143
|
a[e] = zone
|
142
144
|
a
|
143
|
-
|
144
|
-
|
145
|
+
end)
|
146
|
+
end
|
145
147
|
|
146
148
|
sort_by_name ? ::Hash[rv.sort { |a, b| ::ActiveSupport::TimeZone.compare(a[0], b[0]) }] : rv
|
147
149
|
end
|
@@ -281,8 +283,6 @@ module Lazier
|
|
281
283
|
def format_alias(name, zone, reference)
|
282
284
|
if zone.gsub("_", " ") == reference
|
283
285
|
["International Date Line West", "UTC"].include?(name) || name.include?("(US & Canada)") ? name : reference.gsub(/\/.*/, "/#{name}")
|
284
|
-
else
|
285
|
-
nil
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
data/lib/lazier/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,23 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
require "bundler/setup"
|
7
|
+
|
8
|
+
if ENV["COVERAGE"]
|
9
|
+
require "simplecov"
|
10
|
+
require "coveralls"
|
11
|
+
|
12
|
+
Coveralls.wear! if ENV["CI"]
|
13
|
+
|
14
|
+
SimpleCov.start do
|
15
|
+
root = Pathname.new(File.dirname(__FILE__)) + ".."
|
16
|
+
|
17
|
+
add_filter do |src_file|
|
18
|
+
path = Pathname.new(src_file.filename).relative_path_from(root).to_s
|
19
|
+
path !~ /^lib/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
7
24
|
require File.dirname(__FILE__) + "/../lib/lazier"
|
8
25
|
|
9
26
|
::I18n.enforce_available_locales = false
|
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.2.
|
4
|
+
version: 4.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shogun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.15'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
54
|
+
version: '2.15'
|
55
55
|
description: Several Ruby object enhancements.
|
56
56
|
email:
|
57
57
|
- shogun@cowtech.it
|
@@ -120,7 +120,6 @@ files:
|
|
120
120
|
- lib/lazier/version.rb
|
121
121
|
- locales/en.yml
|
122
122
|
- locales/it.yml
|
123
|
-
- spec/coverage_helper.rb
|
124
123
|
- spec/lazier/boolean_spec.rb
|
125
124
|
- spec/lazier/configuration_spec.rb
|
126
125
|
- spec/lazier/datetime_spec.rb
|
@@ -147,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
146
|
requirements:
|
148
147
|
- - ">="
|
149
148
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
149
|
+
version: 2.3.0
|
151
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
151
|
requirements:
|
153
152
|
- - ">="
|
@@ -155,12 +154,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
154
|
version: '0'
|
156
155
|
requirements: []
|
157
156
|
rubyforge_project: lazier
|
158
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.5.1
|
159
158
|
signing_key:
|
160
159
|
specification_version: 4
|
161
160
|
summary: Several Ruby object enhancements.
|
162
161
|
test_files:
|
163
|
-
- spec/coverage_helper.rb
|
164
162
|
- spec/lazier/boolean_spec.rb
|
165
163
|
- spec/lazier/configuration_spec.rb
|
166
164
|
- spec/lazier/datetime_spec.rb
|
data/spec/coverage_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# This file is part of the lazier gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
|
3
|
-
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "pathname"
|
7
|
-
require "simplecov"
|
8
|
-
require "coveralls"
|
9
|
-
|
10
|
-
Coveralls.wear! if ENV["CI"] || ENV["JENKINS_URL"]
|
11
|
-
|
12
|
-
SimpleCov.start do
|
13
|
-
root = Pathname.new(File.dirname(__FILE__)) + ".."
|
14
|
-
|
15
|
-
add_filter do |src_file|
|
16
|
-
path = Pathname.new(src_file.filename).relative_path_from(root).to_s
|
17
|
-
path !~ /^lib/
|
18
|
-
end
|
19
|
-
end
|