active_object 3.0.0 → 3.1.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.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -1
- data/.gitignore +1 -1
- data/.rspec +1 -1
- data/.travis.yml +1 -1
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +17 -3
- data/Rakefile +1 -1
- data/active_object.gemspec +12 -12
- data/bin/console +1 -1
- data/bin/setup +1 -1
- data/lib/active_object/array.rb +3 -5
- data/lib/active_object/date.rb +63 -0
- data/lib/active_object/enumerable.rb +2 -2
- data/lib/active_object/numeric.rb +27 -27
- data/lib/active_object/object.rb +5 -3
- data/lib/active_object/time.rb +64 -0
- data/lib/active_object/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 161b344cfb86cc5d27a34babe38cd5ac595e0ef4
|
4
|
+
data.tar.gz: 8df3cc4a616c35bd0ee8fc3d39ffe960915b0459
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaf2c2d7b0315f196b33705bcb0afaee61916cdd90fa4da4b4b4ce108de7ce928e012af1175686e8d2e08e1a331a651a4846b8560f7e9a9f2f489cfe171aee4d
|
7
|
+
data.tar.gz: a0a23c8780c01154cc7b6c56ab44f2bc0f55f21e2ee33eaabec5f3b3e9202e97260f8c144e2c61ea5da4156cb3b99b147be907bfe77cf5f6fedf9b998a3286e9
|
data/.coveralls.yml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
service_name: travis-ci
|
1
|
+
service_name: travis-ci
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -10,4 +10,4 @@ Project maintainers have the right and responsibility to remove, edit, or reject
|
|
10
10
|
|
11
11
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
12
|
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Highly recommended extensions:
|
|
17
17
|
|
18
18
|
Add this line to your application's Gemfile:
|
19
19
|
|
20
|
-
gem
|
20
|
+
gem "active_object"
|
21
21
|
|
22
22
|
And then execute:
|
23
23
|
|
@@ -1846,6 +1846,18 @@ false.truthy? #=> false
|
|
1846
1846
|
|
1847
1847
|
*Note:* also works with Date class.
|
1848
1848
|
|
1849
|
+
####Count:####
|
1850
|
+
`count_[DURATION]_[TERM]` converts a Date or Time object to format it using a human readable string.
|
1851
|
+
|
1852
|
+
**Durations/Terms**
|
1853
|
+
* seconds, minutes, hours, days, weeks, years, decades, centuries, millenniums
|
1854
|
+
* since, until
|
1855
|
+
|
1856
|
+
```ruby
|
1857
|
+
Date.today.count_hours_since(Date.yesterday) #=> "24.0"
|
1858
|
+
Time.now.count_minutes_until(20.minutes.from_now) #=> "20.0"
|
1859
|
+
```
|
1860
|
+
|
1849
1861
|
####Format:####
|
1850
1862
|
`format` converts a Date or Time object to format it using a human readable string.
|
1851
1863
|
|
@@ -1960,8 +1972,10 @@ Time.now.stamp(:datetime) #=> "January 09, 2014 02:31 pm"
|
|
1960
1972
|
|
1961
1973
|
## Contributing
|
1962
1974
|
|
1963
|
-
|
1975
|
+
Your contribution is welcome.
|
1976
|
+
|
1977
|
+
1. Fork it
|
1964
1978
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
1965
|
-
3. Commit your changes (`git commit -am '
|
1979
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
1966
1980
|
4. Push to the branch (`git push origin my-new-feature`)
|
1967
1981
|
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/active_object.gemspec
CHANGED
@@ -4,24 +4,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require "active_object/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
7
|
+
spec.name = "active_object"
|
8
|
+
spec.version = ActiveObject::VERSION
|
9
|
+
spec.authors = ["Juan Gomez"]
|
10
|
+
spec.email = ["j.gomez@drexed.com"]
|
11
11
|
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
12
|
+
spec.summary = %q{Gem for commonly used ruby object helpers.}
|
13
|
+
spec.description = %q{Class extensions of commonly used ruby object helpers.}
|
14
|
+
spec.homepage = "http://drexed.github.io/active_object"
|
15
|
+
spec.license = "MIT"
|
16
16
|
|
17
|
-
spec.files
|
18
|
-
spec.bindir
|
19
|
-
spec.executables
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler"
|
23
23
|
spec.add_development_dependency "coveralls"
|
24
24
|
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
26
|
spec.add_development_dependency "generator_spec"
|
27
27
|
end
|
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/lib/active_object/array.rb
CHANGED
@@ -31,7 +31,7 @@ module ActiveObject::Array
|
|
31
31
|
def delete_values(*args)
|
32
32
|
result = []
|
33
33
|
args.each { |v| result << delete(v) }
|
34
|
-
|
34
|
+
result
|
35
35
|
end
|
36
36
|
|
37
37
|
def dig(key, *rest)
|
@@ -100,7 +100,7 @@ module ActiveObject::Array
|
|
100
100
|
size = self.size
|
101
101
|
|
102
102
|
if size > 1
|
103
|
-
index = size * percentage / 100.0
|
103
|
+
index = (size * percentage) / 100.0
|
104
104
|
self.sort[index]
|
105
105
|
else
|
106
106
|
self.first
|
@@ -131,7 +131,7 @@ module ActiveObject::Array
|
|
131
131
|
def split(number=nil)
|
132
132
|
if block_given?
|
133
133
|
inject([[]]) do |results, element|
|
134
|
-
yield(element) ? results << [] : results.last << element
|
134
|
+
yield(element) ? (results << []) : (results.last << element)
|
135
135
|
results
|
136
136
|
end
|
137
137
|
else
|
@@ -162,8 +162,6 @@ module ActiveObject::Array
|
|
162
162
|
end
|
163
163
|
|
164
164
|
def to_sentence(options={})
|
165
|
-
options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector)
|
166
|
-
|
167
165
|
default_connectors = {
|
168
166
|
words_connector: ", ",
|
169
167
|
two_words_connector: " and ",
|
data/lib/active_object/date.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
module ActiveObject::Date
|
2
2
|
|
3
|
+
MINUTE = 60.0
|
4
|
+
HOUR = MINUTE * 60.0
|
5
|
+
DAY = HOUR * 24.0
|
6
|
+
WEEK = DAY * 7.0
|
7
|
+
YEAR = DAY * 365.25
|
8
|
+
DECADE = YEAR * 10.0
|
9
|
+
CENTURY = DECADE * 10.0
|
10
|
+
MILLENNIUM = CENTURY * 10.0
|
11
|
+
|
3
12
|
STRING_UNITS = {
|
4
13
|
d: "d", day: "d", day_padded: "d", dd: "-d", Day: "-d", day_unpadded: "-d",
|
5
14
|
ddd: "_d", DAY: "_d", day_blank: "_d", dddd: "j", day_of_the_year: "j",
|
@@ -22,6 +31,60 @@ module ActiveObject::Date
|
|
22
31
|
day: "%B %-d", day_abbr: "%b %-d", day_iso: "%m-%d"
|
23
32
|
}
|
24
33
|
|
34
|
+
def count_centuries_since(time)
|
35
|
+
count_seconds_since(time) / CENTURY
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :count_centuries_until, :count_centuries_since
|
39
|
+
|
40
|
+
def count_days_since(time)
|
41
|
+
count_seconds_since(time) / DAY
|
42
|
+
end
|
43
|
+
|
44
|
+
alias_method :count_days_until, :count_days_since
|
45
|
+
|
46
|
+
def count_decades_since(time)
|
47
|
+
count_seconds_since(time) / DECADE
|
48
|
+
end
|
49
|
+
|
50
|
+
alias_method :count_decades_until, :count_decades_since
|
51
|
+
|
52
|
+
def count_hours_since(time)
|
53
|
+
count_seconds_since(time) / HOUR
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method :count_hours_until, :count_hours_since
|
57
|
+
|
58
|
+
def count_milleniums_since(time)
|
59
|
+
count_seconds_since(time) / MILLENNIUM
|
60
|
+
end
|
61
|
+
|
62
|
+
alias_method :count_milleniums_until, :count_milleniums_since
|
63
|
+
|
64
|
+
def count_minutes_since(time)
|
65
|
+
count_seconds_since(time) / MINUTE
|
66
|
+
end
|
67
|
+
|
68
|
+
alias_method :count_minutes_until, :count_minutes_since
|
69
|
+
|
70
|
+
def count_seconds_since(time)
|
71
|
+
(to_time.to_f - time.to_time.to_f).abs
|
72
|
+
end
|
73
|
+
|
74
|
+
alias_method :count_seconds_until, :count_seconds_since
|
75
|
+
|
76
|
+
def count_weeks_since(time)
|
77
|
+
count_seconds_since(time) / WEEK
|
78
|
+
end
|
79
|
+
|
80
|
+
alias_method :count_weeks_until, :count_weeks_since
|
81
|
+
|
82
|
+
def count_years_since(time)
|
83
|
+
count_seconds_since(time) / YEAR
|
84
|
+
end
|
85
|
+
|
86
|
+
alias_method :count_years_until, :count_years_since
|
87
|
+
|
25
88
|
def format(string)
|
26
89
|
delimiters = string.scan(/\W+/)
|
27
90
|
formatters = string.scan(/[a-z0-9_]+/i)
|
@@ -107,10 +107,10 @@ module Enumerable
|
|
107
107
|
alias_method :average, :mean
|
108
108
|
|
109
109
|
def median(identity=0)
|
110
|
-
collection_length
|
110
|
+
collection_length = length.to_f
|
111
111
|
collection_sorted = sort
|
112
112
|
|
113
|
-
return(identity) unless collection_length > 0
|
113
|
+
return(identity) unless collection_length > 0.0
|
114
114
|
|
115
115
|
if (collection_length % 2).zero?
|
116
116
|
(collection_sorted[(collection_length / 2.0) -1.0] + collection_sorted[collection_length / 2.0]) / 2.0
|
@@ -1,37 +1,37 @@
|
|
1
1
|
module ActiveObject::Numeric
|
2
2
|
|
3
3
|
MILLI = 0.001
|
4
|
-
CENTI = MILLI * 10
|
5
|
-
DECI = CENTI * 10
|
6
|
-
DECA = 10
|
7
|
-
HECTO = DECA * 10
|
8
|
-
KILO = HECTO * 10
|
9
|
-
|
10
|
-
KILOBYTE = 1024
|
11
|
-
MEGABYTE = KILOBYTE * 1024
|
12
|
-
GIGABYTE = MEGABYTE * 1024
|
13
|
-
TERABYTE = GIGABYTE * 1024
|
14
|
-
PETABYTE = TERABYTE * 1024
|
15
|
-
EXABYTE = PETABYTE * 1024
|
16
|
-
|
17
|
-
FEET = 12
|
18
|
-
YARD = FEET * 3
|
19
|
-
MILE = YARD * 1760
|
4
|
+
CENTI = MILLI * 10.0
|
5
|
+
DECI = CENTI * 10.0
|
6
|
+
DECA = 10.0
|
7
|
+
HECTO = DECA * 10.0
|
8
|
+
KILO = HECTO * 10.0
|
9
|
+
|
10
|
+
KILOBYTE = 1024.0
|
11
|
+
MEGABYTE = KILOBYTE * 1024.0
|
12
|
+
GIGABYTE = MEGABYTE * 1024.0
|
13
|
+
TERABYTE = GIGABYTE * 1024.0
|
14
|
+
PETABYTE = TERABYTE * 1024.0
|
15
|
+
EXABYTE = PETABYTE * 1024.0
|
16
|
+
|
17
|
+
FEET = 12.0
|
18
|
+
YARD = FEET * 3.0
|
19
|
+
MILE = YARD * 1760.0
|
20
20
|
NAUTICAL_MILE = MILE * 1.15078
|
21
21
|
|
22
|
-
METRIC_TON = KILO * 1000
|
23
|
-
POUND = 16
|
24
|
-
STONE = POUND * 14
|
25
|
-
TON = POUND * 2000
|
22
|
+
METRIC_TON = KILO * 1000.0
|
23
|
+
POUND = 16.0
|
24
|
+
STONE = POUND * 14.0
|
25
|
+
TON = POUND * 2000.0
|
26
26
|
|
27
|
-
MINUTE = 60
|
28
|
-
HOUR = MINUTE * 60
|
29
|
-
DAY = HOUR * 24
|
30
|
-
WEEK = DAY * 7
|
27
|
+
MINUTE = 60.0
|
28
|
+
HOUR = MINUTE * 60.0
|
29
|
+
DAY = HOUR * 24.0
|
30
|
+
WEEK = DAY * 7.0
|
31
31
|
YEAR = DAY * 365.25
|
32
|
-
DECADE = YEAR * 10
|
33
|
-
CENTURY = DECADE * 10
|
34
|
-
MILLENNIUM = CENTURY * 10
|
32
|
+
DECADE = YEAR * 10.0
|
33
|
+
CENTURY = DECADE * 10.0
|
34
|
+
MILLENNIUM = CENTURY * 10.0
|
35
35
|
|
36
36
|
BYTE_KEYS = [
|
37
37
|
:byte, :bytes, :kilobyte, :kilobytes, :megabyte, :megabytes, :gigabyte,
|
data/lib/active_object/object.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module ActiveObject::Object
|
2
|
+
FALSE_VALUES = [false, 0, "0", "false", "FALSE", "f", "F"]
|
3
|
+
TRUE_VALUES = [true, 1, "1", "true", "TRUE", "t", "T"]
|
2
4
|
|
3
5
|
def array?
|
4
6
|
is_a?(Array)
|
@@ -11,7 +13,7 @@ module ActiveObject::Object
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def boolean?
|
14
|
-
|
16
|
+
TRUE_VALUES.include?(self) || FALSE_VALUES.include?(self)
|
15
17
|
end
|
16
18
|
|
17
19
|
def false?
|
@@ -19,7 +21,7 @@ module ActiveObject::Object
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def falsey?
|
22
|
-
|
24
|
+
nil? || FALSE_VALUES.include?(self)
|
23
25
|
end
|
24
26
|
|
25
27
|
def float?
|
@@ -71,7 +73,7 @@ module ActiveObject::Object
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def truthy?
|
74
|
-
|
76
|
+
TRUE_VALUES.include?(self)
|
75
77
|
end
|
76
78
|
|
77
79
|
def try(*a, &b)
|
data/lib/active_object/time.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
module ActiveObject::Time
|
2
2
|
|
3
|
+
MINUTE = 60.0
|
4
|
+
HOUR = MINUTE * 60.0
|
5
|
+
DAY = HOUR * 24.0
|
6
|
+
WEEK = DAY * 7.0
|
7
|
+
YEAR = DAY * 365.25
|
8
|
+
DECADE = YEAR * 10.0
|
9
|
+
CENTURY = DECADE * 10.0
|
10
|
+
MILLENNIUM = CENTURY * 10.0
|
11
|
+
|
3
12
|
KEY_UNITS = {
|
4
13
|
month: "%m", month_padded: "%m", month_unpadded: "%-m", month_blank: "%_m",
|
5
14
|
month_name: "%B", month_name_abbr: "%b", month_year: "%m %Y",
|
@@ -45,6 +54,61 @@ module ActiveObject::Time
|
|
45
54
|
time_zone_offset_full: "::z", zzzz: "Z", time_zone_name: "Z"
|
46
55
|
}
|
47
56
|
|
57
|
+
def count_centuries_since(time)
|
58
|
+
count_seconds_since(time) / CENTURY
|
59
|
+
end
|
60
|
+
|
61
|
+
alias_method :count_centuries_until, :count_centuries_since
|
62
|
+
|
63
|
+
def count_days_since(time)
|
64
|
+
count_seconds_since(time) / DAY
|
65
|
+
end
|
66
|
+
|
67
|
+
alias_method :count_days_until, :count_days_since
|
68
|
+
|
69
|
+
def count_decades_since(time)
|
70
|
+
count_seconds_since(time) / DECADE
|
71
|
+
end
|
72
|
+
|
73
|
+
alias_method :count_decades_until, :count_decades_since
|
74
|
+
|
75
|
+
def count_hours_since(time)
|
76
|
+
count_seconds_since(time) / HOUR
|
77
|
+
end
|
78
|
+
|
79
|
+
alias_method :count_hours_until, :count_hours_since
|
80
|
+
|
81
|
+
def count_milleniums_since(time)
|
82
|
+
count_seconds_since(time) / MILLENNIUM
|
83
|
+
end
|
84
|
+
|
85
|
+
alias_method :count_milleniums_until, :count_milleniums_since
|
86
|
+
|
87
|
+
def count_minutes_since(time)
|
88
|
+
count_seconds_since(time) / MINUTE
|
89
|
+
end
|
90
|
+
|
91
|
+
alias_method :count_minutes_until, :count_minutes_since
|
92
|
+
|
93
|
+
def count_seconds_since(time)
|
94
|
+
time = time.to_time if time.respond_to?(:to_time)
|
95
|
+
(to_f - time.to_f).abs
|
96
|
+
end
|
97
|
+
|
98
|
+
alias_method :count_seconds_until, :count_seconds_since
|
99
|
+
|
100
|
+
def count_weeks_since(time)
|
101
|
+
count_seconds_since(time) / WEEK
|
102
|
+
end
|
103
|
+
|
104
|
+
alias_method :count_weeks_until, :count_weeks_since
|
105
|
+
|
106
|
+
def count_years_since(time)
|
107
|
+
count_seconds_since(time) / YEAR
|
108
|
+
end
|
109
|
+
|
110
|
+
alias_method :count_years_until, :count_years_since
|
111
|
+
|
48
112
|
def format(string)
|
49
113
|
delimiters = string.scan(/\W+/)
|
50
114
|
formatters = string.scan(/[a-z0-9_]+/i)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: generator_spec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|