casual_support 1.0.0 → 2.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.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +52 -17
- data/Rakefile +13 -0
- data/benchmarks/comparable/at_least.rb +9 -0
- data/benchmarks/comparable/at_most.rb +9 -0
- data/benchmarks/hash/putbang.rb +13 -0
- data/benchmarks/integer/to_hex.rb +34 -0
- data/benchmarks/string/after.rb +22 -0
- data/benchmarks/string/after_last.rb +22 -0
- data/benchmarks/string/before.rb +23 -0
- data/benchmarks/string/before_last.rb +22 -0
- data/benchmarks/string/between.rb +21 -0
- data/benchmarks/string/drop.rb +18 -0
- data/benchmarks/string/first.rb +23 -0
- data/benchmarks/string/from.rb +15 -0
- data/benchmarks/string/last.rb +15 -0
- data/benchmarks/string/prefix.rb +12 -0
- data/benchmarks/string/suffix.rb +12 -0
- data/benchmarks/string/to.rb +15 -0
- data/benchmarks/time/to_hms.rb +12 -0
- data/benchmarks/time/to_ymd.rb +12 -0
- data/casual_support.gemspec +4 -3
- data/lib/casual_support.rb +8 -8
- data/lib/casual_support/comparable.rb +3 -0
- data/lib/casual_support/comparable/at_least.rb +11 -0
- data/lib/casual_support/comparable/at_most.rb +13 -0
- data/lib/casual_support/comparable/clamp.rb +16 -0
- data/lib/casual_support/date.rb +1 -1
- data/lib/casual_support/date/to_ymd.rb +1 -1
- data/lib/casual_support/enumerable.rb +2 -2
- data/lib/casual_support/enumerable/index_to.rb +2 -2
- data/lib/casual_support/hash.rb +1 -1
- data/lib/casual_support/hash/putbang.rb +15 -0
- data/lib/casual_support/integer.rb +1 -1
- data/lib/casual_support/integer/to_hex.rb +2 -8
- data/lib/casual_support/string.rb +13 -4
- data/lib/casual_support/string/after.rb +15 -0
- data/lib/casual_support/string/after_last.rb +14 -0
- data/lib/casual_support/string/before.rb +14 -0
- data/lib/casual_support/string/before_last.rb +15 -0
- data/lib/casual_support/string/between.rb +16 -0
- data/lib/casual_support/string/drop.rb +2 -1
- data/lib/casual_support/string/first.rb +17 -0
- data/lib/casual_support/string/from.rb +8 -0
- data/lib/casual_support/string/last.rb +18 -0
- data/lib/casual_support/string/lchomp.rb +16 -0
- data/lib/casual_support/string/prefix.rb +13 -0
- data/lib/casual_support/string/suffix.rb +13 -0
- data/lib/casual_support/string/to.rb +9 -0
- data/lib/casual_support/time.rb +2 -1
- data/lib/casual_support/time/to_hms.rb +14 -0
- data/lib/casual_support/time/to_ymd.rb +14 -0
- data/lib/casual_support/version.rb +1 -1
- metadata +71 -18
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/casual_support/hash/setbang.rb +0 -16
- data/lib/casual_support/numeric.rb +0 -2
- data/lib/casual_support/numeric/at_least_most.rb +0 -21
- data/lib/casual_support/numeric/constrain.rb +0 -16
- data/lib/casual_support/string/before_after.rb +0 -59
- data/lib/casual_support/string/first_last.rb +0 -15
- data/lib/casual_support/string/from_to.rb +0 -15
- data/lib/casual_support/time/ymd_hms.rb +0 -27
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: casual_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Hefner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '11.1'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '11.1'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: minitest
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,8 +72,35 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '5.0'
|
75
|
-
|
76
|
-
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: yard
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0.9'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0.9'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: benchmark-inputs
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.0'
|
103
|
+
description:
|
77
104
|
email:
|
78
105
|
- jonathan.hefner@gmail.com
|
79
106
|
executables: []
|
@@ -86,29 +113,56 @@ files:
|
|
86
113
|
- LICENSE.txt
|
87
114
|
- README.md
|
88
115
|
- Rakefile
|
89
|
-
-
|
90
|
-
-
|
116
|
+
- benchmarks/comparable/at_least.rb
|
117
|
+
- benchmarks/comparable/at_most.rb
|
118
|
+
- benchmarks/hash/putbang.rb
|
119
|
+
- benchmarks/integer/to_hex.rb
|
120
|
+
- benchmarks/string/after.rb
|
121
|
+
- benchmarks/string/after_last.rb
|
122
|
+
- benchmarks/string/before.rb
|
123
|
+
- benchmarks/string/before_last.rb
|
124
|
+
- benchmarks/string/between.rb
|
125
|
+
- benchmarks/string/drop.rb
|
126
|
+
- benchmarks/string/first.rb
|
127
|
+
- benchmarks/string/from.rb
|
128
|
+
- benchmarks/string/last.rb
|
129
|
+
- benchmarks/string/prefix.rb
|
130
|
+
- benchmarks/string/suffix.rb
|
131
|
+
- benchmarks/string/to.rb
|
132
|
+
- benchmarks/time/to_hms.rb
|
133
|
+
- benchmarks/time/to_ymd.rb
|
91
134
|
- casual_support.gemspec
|
92
135
|
- lib/casual_support.rb
|
136
|
+
- lib/casual_support/comparable.rb
|
137
|
+
- lib/casual_support/comparable/at_least.rb
|
138
|
+
- lib/casual_support/comparable/at_most.rb
|
139
|
+
- lib/casual_support/comparable/clamp.rb
|
93
140
|
- lib/casual_support/date.rb
|
94
141
|
- lib/casual_support/date/to_ymd.rb
|
95
142
|
- lib/casual_support/enumerable.rb
|
96
143
|
- lib/casual_support/enumerable/duplicates.rb
|
97
144
|
- lib/casual_support/enumerable/index_to.rb
|
98
145
|
- lib/casual_support/hash.rb
|
99
|
-
- lib/casual_support/hash/
|
146
|
+
- lib/casual_support/hash/putbang.rb
|
100
147
|
- lib/casual_support/integer.rb
|
101
148
|
- lib/casual_support/integer/to_hex.rb
|
102
|
-
- lib/casual_support/numeric.rb
|
103
|
-
- lib/casual_support/numeric/at_least_most.rb
|
104
|
-
- lib/casual_support/numeric/constrain.rb
|
105
149
|
- lib/casual_support/string.rb
|
106
|
-
- lib/casual_support/string/
|
150
|
+
- lib/casual_support/string/after.rb
|
151
|
+
- lib/casual_support/string/after_last.rb
|
152
|
+
- lib/casual_support/string/before.rb
|
153
|
+
- lib/casual_support/string/before_last.rb
|
154
|
+
- lib/casual_support/string/between.rb
|
107
155
|
- lib/casual_support/string/drop.rb
|
108
|
-
- lib/casual_support/string/
|
109
|
-
- lib/casual_support/string/
|
156
|
+
- lib/casual_support/string/first.rb
|
157
|
+
- lib/casual_support/string/from.rb
|
158
|
+
- lib/casual_support/string/last.rb
|
159
|
+
- lib/casual_support/string/lchomp.rb
|
160
|
+
- lib/casual_support/string/prefix.rb
|
161
|
+
- lib/casual_support/string/suffix.rb
|
162
|
+
- lib/casual_support/string/to.rb
|
110
163
|
- lib/casual_support/time.rb
|
111
|
-
- lib/casual_support/time/
|
164
|
+
- lib/casual_support/time/to_hms.rb
|
165
|
+
- lib/casual_support/time/to_ymd.rb
|
112
166
|
- lib/casual_support/version.rb
|
113
167
|
homepage: https://github.com/jonathanhefner/casual_support
|
114
168
|
licenses:
|
@@ -133,6 +187,5 @@ rubyforge_project:
|
|
133
187
|
rubygems_version: 2.4.8
|
134
188
|
signing_key:
|
135
189
|
specification_version: 4
|
136
|
-
summary: Utility
|
190
|
+
summary: Utility extensions to core objects, a la Active Support
|
137
191
|
test_files: []
|
138
|
-
has_rdoc:
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "casual_support"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
data/bin/setup
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
|
3
|
-
# Sets a value like +Hash#[]=+, but returns the modified Hash instead
|
4
|
-
# of the value. Useful with +#reduce+, and 2x faster than using
|
5
|
-
# an equivalent +Hash#merge!+ (see
|
6
|
-
# benchmark[https://github.com/JuanitoFatas/fast-ruby#hashmerge-vs-hash-code]).
|
7
|
-
#
|
8
|
-
# @param key
|
9
|
-
# @param value
|
10
|
-
# @return [Hash] the modified hash
|
11
|
-
def set!(key, value)
|
12
|
-
self[key] = value
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class Numeric
|
2
|
-
|
3
|
-
# Enforces a lower bound for a number.
|
4
|
-
#
|
5
|
-
# @param [Numeric] limit lower bound
|
6
|
-
# @return [Numeric] the number constrained by the lower bound
|
7
|
-
def at_least(limit)
|
8
|
-
self < limit ? limit : self
|
9
|
-
end
|
10
|
-
|
11
|
-
# Enforces an upper bound for a number.
|
12
|
-
#
|
13
|
-
# @param [Numeric] limit upper bound
|
14
|
-
# @return [Numeric] the number constrained by the upper bound
|
15
|
-
def at_most(limit)
|
16
|
-
self > limit ? limit : self
|
17
|
-
end
|
18
|
-
|
19
|
-
alias_method :cap, :at_most
|
20
|
-
|
21
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class Numeric
|
2
|
-
|
3
|
-
# Constrains a number to a closed interval.
|
4
|
-
#
|
5
|
-
# @param [Numeric] low lower bound
|
6
|
-
# @param [Numeric] high upper bound
|
7
|
-
# @return [Numeric] the number constrained to the bounds
|
8
|
-
def constrain(low, high)
|
9
|
-
return low if self < low
|
10
|
-
return high if self > high
|
11
|
-
self
|
12
|
-
end
|
13
|
-
|
14
|
-
alias_method :clamp, :constrain
|
15
|
-
|
16
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
# Searches for the first occurrence of a delimiter, and returns the
|
4
|
-
# portion of the string before that. If the delimiter is not found,
|
5
|
-
# returns the original string.
|
6
|
-
#
|
7
|
-
# Semantically equivalent to:
|
8
|
-
# split(delim).first
|
9
|
-
#
|
10
|
-
# @param [String] delim delimiter to search for
|
11
|
-
# @return [String] portion of the string before the first +delim+
|
12
|
-
def before(delim)
|
13
|
-
i = self.index(delim)
|
14
|
-
i ? self.first(i) : self
|
15
|
-
end
|
16
|
-
|
17
|
-
# Searches for the last occurrence of a delimiter, and returns the
|
18
|
-
# portion of the string before that. If the delimiter is not found,
|
19
|
-
# returns the original string.
|
20
|
-
#
|
21
|
-
# Semantically equivalent to:
|
22
|
-
# split(delim)[0..-2].join(delim)
|
23
|
-
#
|
24
|
-
# @param [String] delim delimiter to search for
|
25
|
-
# @return [String] portion of the string before the last +delim+
|
26
|
-
def before_last(delim)
|
27
|
-
i = self.rindex(delim)
|
28
|
-
i ? self.first(i) : self
|
29
|
-
end
|
30
|
-
|
31
|
-
# Searches for the first occurrence of a delimiter, and returns the
|
32
|
-
# portion of the string after that. If the delimiter is not found,
|
33
|
-
# returns the original string.
|
34
|
-
#
|
35
|
-
# Semantically equivalent to:
|
36
|
-
# split(delim, 2).last
|
37
|
-
#
|
38
|
-
# @param [String] delim delimiter to search for
|
39
|
-
# @return [String] portion of the string after the first +delim+
|
40
|
-
def after(delim)
|
41
|
-
i = self.index(delim)
|
42
|
-
i ? self.drop(i + delim.length) : self
|
43
|
-
end
|
44
|
-
|
45
|
-
# Searches for the last occurrence of a delimiter, and returns the
|
46
|
-
# portion of the string after that. If the delimiter is not found,
|
47
|
-
# returns the original string.
|
48
|
-
#
|
49
|
-
# Semantically equivalent to:
|
50
|
-
# split(delim).last
|
51
|
-
#
|
52
|
-
# @param [String] delim delimiter to search for
|
53
|
-
# @return [String] portion of the string after the last +delim+
|
54
|
-
def after_last(delim)
|
55
|
-
i = self.rindex(delim)
|
56
|
-
i ? self.drop(i + delim.length) : self
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
# This replaces Active Support's +String#first+, but it returns an
|
4
|
-
# empty string when given a negative argument. It is ~75% faster.
|
5
|
-
def first(limit = 1)
|
6
|
-
limit <= 0 ? '' : self[0, limit]
|
7
|
-
end
|
8
|
-
|
9
|
-
# This replaces Active Support's +String#last+, but it returns an
|
10
|
-
# empty string when given a negative argument. It is ~75% faster.
|
11
|
-
def last(limit = 1)
|
12
|
-
limit <= 0 ? '' : self[length - limit, length]
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
# This replaces Active Support's +String#from+. It is ~40% faster.
|
4
|
-
def from(position)
|
5
|
-
position += self.length if position < 0
|
6
|
-
self[position, length]
|
7
|
-
end
|
8
|
-
|
9
|
-
# This replaces Active Support's +String#to+. It is ~40% faster.
|
10
|
-
def to(position)
|
11
|
-
position += self.length if position < 0
|
12
|
-
self[0, position + 1]
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
class Time
|
2
|
-
|
3
|
-
# Formats time as "YYYY-MM-DD" (e.g. "1999-12-31"). Equivalent to
|
4
|
-
# +strftime("%Y-%m-%d")+, but ~6% faster (or ~18% if the format
|
5
|
-
# string is an un-frozen literal, due to GC).
|
6
|
-
#
|
7
|
-
# @return [String] the time formatted as "YYYY-MM-DD"
|
8
|
-
def to_ymd
|
9
|
-
# Date#strftime appears to be **much** faster than Time#strftime
|
10
|
-
# (nearly 3x faster!). If Time#strftime becomes optimized to that
|
11
|
-
# level in the future, it should be used instead of sprintf.
|
12
|
-
sprintf('%04d-%02d-%02d'.freeze, year, month, day)
|
13
|
-
end
|
14
|
-
|
15
|
-
# Formats time as "HH:MM:SS" (e.g. "23:59:59"). Equivalent to
|
16
|
-
# +strftime("%H:%M:%S")+, but ~10% faster (or ~20% if the format
|
17
|
-
# string is an un-frozen literal, due to GC).
|
18
|
-
#
|
19
|
-
# @return [String] the time formatted as "HH:MM:SS"
|
20
|
-
def to_hms
|
21
|
-
# Date#strftime appears to be **much** faster than Time#strftime
|
22
|
-
# (nearly 3x faster!). If Time#strftime becomes optimized to that
|
23
|
-
# level in the future, it should be used instead of sprintf.
|
24
|
-
sprintf('%02d:%02d:%02d'.freeze, hour, min, sec)
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|