casual_support 3.0.2 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +3 -3
- data/CHANGELOG.md +22 -3
- data/Gemfile +5 -1
- data/README.md +34 -62
- data/Rakefile +0 -13
- data/casual_support.gemspec +11 -15
- data/lib/casual_support.rb +0 -4
- data/lib/casual_support/date/to_ymd.rb +1 -1
- data/lib/casual_support/enumerable/index_to.rb +5 -5
- data/lib/casual_support/hash/displace.rb +2 -2
- data/lib/casual_support/hash/putbang.rb +3 -3
- data/lib/casual_support/string.rb +0 -5
- data/lib/casual_support/string/after.rb +2 -2
- data/lib/casual_support/string/after_last.rb +2 -2
- data/lib/casual_support/string/before.rb +2 -2
- data/lib/casual_support/string/before_last.rb +2 -2
- data/lib/casual_support/string/between.rb +2 -2
- data/lib/casual_support/string/prefix.rb +3 -3
- data/lib/casual_support/string/suffix.rb +2 -2
- data/lib/casual_support/struct/assign_attributes.rb +1 -1
- data/lib/casual_support/struct/from_h.rb +7 -4
- data/lib/casual_support/version.rb +1 -1
- metadata +10 -105
- data/lib/casual_support/boolean.rb +0 -1
- data/lib/casual_support/boolean/to_z.rb +0 -22
- data/lib/casual_support/comparable.rb +0 -2
- data/lib/casual_support/comparable/at_least.rb +0 -15
- data/lib/casual_support/comparable/at_most.rb +0 -17
- data/lib/casual_support/integer.rb +0 -1
- data/lib/casual_support/integer/to_hex.rb +0 -21
- data/lib/casual_support/numeric.rb +0 -1
- data/lib/casual_support/numeric/sign.rb +0 -15
- data/lib/casual_support/string/drop.rb +0 -20
- data/lib/casual_support/string/first.rb +0 -34
- data/lib/casual_support/string/from.rb +0 -24
- data/lib/casual_support/string/last.rb +0 -33
- data/lib/casual_support/string/to.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0b92ba05be9a6f0ad71a911c435c78d450f06c094108e07b9bad99bc87ae512
|
4
|
+
data.tar.gz: 893f5f3e708acd70741c6fd688463aad826f1eacd426bd48ec7b30c820ac8768
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 944da5f33d43a08cc3af8649123b8577e3c4fe504584c86d5aa31afd514c5a9112af504c8aca204f11a08c7ae078d3d9f9c6125dfaf8a3e45c6f2e80fa98d70f
|
7
|
+
data.tar.gz: 2b6af778597dc30e0bb378d402c5a5c4504b4064b1f44bdcc38ba6a57014bd2bf74ff529579808d62d05ce5151717a6fa9bea18f600d2560f904ab545a5b63c2
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 4.0.0
|
2
|
+
|
3
|
+
* [BREAKING] Drop support for Ruby < 2.6
|
4
|
+
* [BREAKING] Remove `String#first` and `String#last`
|
5
|
+
* Remove `String#to` and `String#from`
|
6
|
+
* Remove Active Support dependency
|
7
|
+
* [BREAKING] Remove `String#drop`
|
8
|
+
* Use `string[n..]` instead
|
9
|
+
* [BREAKING] Remove `Comparable#at_least` and `Comparable#at_most`
|
10
|
+
* Use `value.clamp(limit..)` and `value.clamp(..limit)` instead
|
11
|
+
* [BREAKING] Remove `Integer#to_hex`
|
12
|
+
* Use `("%0#{width}x" % int)` instead
|
13
|
+
* [BREAKING] Remove `Numeric#sign`
|
14
|
+
* Use `(num <=> 0)` instead
|
15
|
+
* [BREAKING] Remove `Boolean#to_z`
|
16
|
+
* Use `(bool ? 1 : 0)` instead
|
17
|
+
|
18
|
+
|
1
19
|
## 3.0.2
|
2
20
|
|
3
21
|
* Add `Date#to_hms` dummy method
|
@@ -13,9 +31,10 @@
|
|
13
31
|
## 3.0.0
|
14
32
|
|
15
33
|
* [BREAKING] Remove block param from `Enumerable#duplicates`
|
16
|
-
* [BREAKING] Remove `Comparable#clamp
|
17
|
-
*
|
18
|
-
|
34
|
+
* [BREAKING] Remove `Comparable#clamp`
|
35
|
+
* Native in Ruby 2.4
|
36
|
+
* [BREAKING] Remove `String#lchomp`
|
37
|
+
* Native in Ruby 2.5 as `String#delete_prefix`
|
19
38
|
* Add `Numeric#sign`
|
20
39
|
* Add `Boolean#to_z`
|
21
40
|
* Add `Hash#displace`
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,72 +1,45 @@
|
|
1
|
-
# casual_support
|
2
|
-
|
3
|
-
Utility methods as extensions to Ruby
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
-
|
10
|
-
|
11
|
-
-
|
12
|
-
|
13
|
-
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
[
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
-
|
23
|
-
- [#
|
24
|
-
- [
|
25
|
-
- [#
|
26
|
-
|
27
|
-
- [
|
28
|
-
- [
|
29
|
-
|
30
|
-
- [
|
31
|
-
- [#
|
32
|
-
- [#index_to](http://www.rubydoc.info/gems/casual_support/Enumerable:index_to)
|
33
|
-
- [Hash](http://www.rubydoc.info/gems/casual_support/Hash)
|
34
|
-
- [#displace](http://www.rubydoc.info/gems/casual_support/Hash:displace)
|
35
|
-
- [#put!](http://www.rubydoc.info/gems/casual_support/Hash:put%21)
|
36
|
-
- [Integer](http://www.rubydoc.info/gems/casual_support/Integer)
|
37
|
-
- [#to_hex](http://www.rubydoc.info/gems/casual_support/Integer:to_hex)
|
38
|
-
- [Numeric](http://www.rubydoc.info/gems/casual_support/Numeric)
|
39
|
-
- [#sign](http://www.rubydoc.info/gems/casual_support/Numeric:sign)
|
40
|
-
- [String](http://www.rubydoc.info/gems/casual_support/String)
|
41
|
-
- [#after](http://www.rubydoc.info/gems/casual_support/String:after)
|
42
|
-
- [#after_last](http://www.rubydoc.info/gems/casual_support/String:after_last)
|
43
|
-
- [#before](http://www.rubydoc.info/gems/casual_support/String:before)
|
44
|
-
- [#before_last](http://www.rubydoc.info/gems/casual_support/String:before_last)
|
45
|
-
- [#between](http://www.rubydoc.info/gems/casual_support/String:between)
|
46
|
-
- [#drop](http://www.rubydoc.info/gems/casual_support/String:drop)
|
47
|
-
- [#first](http://www.rubydoc.info/gems/casual_support/String:first)
|
48
|
-
- [#from](http://www.rubydoc.info/gems/casual_support/String:from)
|
49
|
-
- [#last](http://www.rubydoc.info/gems/casual_support/String:last)
|
50
|
-
- [#prefix](http://www.rubydoc.info/gems/casual_support/String:prefix)
|
51
|
-
- [#suffix](http://www.rubydoc.info/gems/casual_support/String:suffix)
|
52
|
-
- [#to](http://www.rubydoc.info/gems/casual_support/String:to)
|
53
|
-
- [Struct](http://www.rubydoc.info/gems/casual_support/Struct)
|
54
|
-
- [#assign_attributes](http://www.rubydoc.info/gems/casual_support/Struct:assign_attributes)
|
55
|
-
- [.from_h](http://www.rubydoc.info/gems/casual_support/Struct.from_h)
|
56
|
-
- [Time](http://www.rubydoc.info/gems/casual_support/Time)
|
57
|
-
- [#to_hms](http://www.rubydoc.info/gems/casual_support/Time:to_hms)
|
58
|
-
- [#to_ymd](http://www.rubydoc.info/gems/casual_support/Time:to_ymd)
|
1
|
+
# casual_support [![Build Status](https://travis-ci.org/jonathanhefner/casual_support.svg?branch=master)](https://travis-ci.org/jonathanhefner/casual_support)
|
2
|
+
|
3
|
+
Utility methods as extensions to core Ruby objects, a la
|
4
|
+
[Active Support](https://guides.rubyonrails.org/active_support_core_extensions.html).
|
5
|
+
|
6
|
+
|
7
|
+
## API
|
8
|
+
|
9
|
+
- [Date](https://www.rubydoc.info/gems/casual_support/Date)
|
10
|
+
- [#to_hms](https://www.rubydoc.info/gems/casual_support/Date:to_hms)
|
11
|
+
- [#to_ymd](https://www.rubydoc.info/gems/casual_support/Date:to_ymd)
|
12
|
+
- [Enumerable](https://www.rubydoc.info/gems/casual_support/Enumerable)
|
13
|
+
- [#duplicates](https://www.rubydoc.info/gems/casual_support/Enumerable:duplicates)
|
14
|
+
- [#index_to](https://www.rubydoc.info/gems/casual_support/Enumerable:index_to)
|
15
|
+
- [Hash](https://www.rubydoc.info/gems/casual_support/Hash)
|
16
|
+
- [#displace](https://www.rubydoc.info/gems/casual_support/Hash:displace)
|
17
|
+
- [#put!](https://www.rubydoc.info/gems/casual_support/Hash:put%21)
|
18
|
+
- [String](https://www.rubydoc.info/gems/casual_support/String)
|
19
|
+
- [#after](https://www.rubydoc.info/gems/casual_support/String:after)
|
20
|
+
- [#after_last](https://www.rubydoc.info/gems/casual_support/String:after_last)
|
21
|
+
- [#before](https://www.rubydoc.info/gems/casual_support/String:before)
|
22
|
+
- [#before_last](https://www.rubydoc.info/gems/casual_support/String:before_last)
|
23
|
+
- [#between](https://www.rubydoc.info/gems/casual_support/String:between)
|
24
|
+
- [#prefix](https://www.rubydoc.info/gems/casual_support/String:prefix)
|
25
|
+
- [#suffix](https://www.rubydoc.info/gems/casual_support/String:suffix)
|
26
|
+
- [Struct](https://www.rubydoc.info/gems/casual_support/Struct)
|
27
|
+
- [#assign_attributes](https://www.rubydoc.info/gems/casual_support/Struct:assign_attributes)
|
28
|
+
- [.from_h](https://www.rubydoc.info/gems/casual_support/Struct.from_h)
|
29
|
+
- [Time](https://www.rubydoc.info/gems/casual_support/Time)
|
30
|
+
- [#to_hms](https://www.rubydoc.info/gems/casual_support/Time:to_hms)
|
31
|
+
- [#to_ymd](https://www.rubydoc.info/gems/casual_support/Time:to_ymd)
|
59
32
|
|
60
33
|
|
61
34
|
## Installation
|
62
35
|
|
63
|
-
Install
|
36
|
+
Install the [gem](https://rubygems.org/gems/casual_support):
|
64
37
|
|
65
38
|
```bash
|
66
39
|
$ gem install casual_support
|
67
40
|
```
|
68
41
|
|
69
|
-
Then require in your Ruby
|
42
|
+
Then require in your Ruby code:
|
70
43
|
|
71
44
|
```ruby
|
72
45
|
require "casual_support"
|
@@ -75,8 +48,7 @@ require "casual_support"
|
|
75
48
|
|
76
49
|
## Contributing
|
77
50
|
|
78
|
-
Run `rake test` to run the tests.
|
79
|
-
interactive prompt that pre-loads the project code.
|
51
|
+
Run `rake test` to run the tests.
|
80
52
|
|
81
53
|
|
82
54
|
## License
|
data/Rakefile
CHANGED
@@ -1,18 +1,5 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rake/testtask"
|
3
|
-
require "yard"
|
4
|
-
|
5
|
-
|
6
|
-
desc "Launch IRB with this gem pre-loaded"
|
7
|
-
task :irb do
|
8
|
-
require "casual_support"
|
9
|
-
require "irb"
|
10
|
-
ARGV.clear
|
11
|
-
IRB.start
|
12
|
-
end
|
13
|
-
|
14
|
-
YARD::Rake::YardocTask.new(:doc) do |t|
|
15
|
-
end
|
16
3
|
|
17
4
|
Rake::TestTask.new(:test) do |t|
|
18
5
|
t.libs << "test"
|
data/casual_support.gemspec
CHANGED
@@ -1,30 +1,26 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path("../lib", __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "casual_support/version"
|
1
|
+
require_relative "lib/casual_support/version"
|
5
2
|
|
6
3
|
Gem::Specification.new do |spec|
|
7
4
|
spec.name = "casual_support"
|
8
5
|
spec.version = CasualSupport::VERSION
|
9
6
|
spec.authors = ["Jonathan Hefner"]
|
10
|
-
spec.email = ["jonathan
|
7
|
+
spec.email = ["jonathan@hefner.pro"]
|
11
8
|
|
12
9
|
spec.summary = %q{Utility extensions to core objects, a la Active Support}
|
13
10
|
spec.homepage = "https://github.com/jonathanhefner/casual_support"
|
14
11
|
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = ">= 2.6"
|
15
13
|
|
16
|
-
spec.
|
17
|
-
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
16
|
+
spec.metadata["changelog_uri"] = spec.metadata["source_code_uri"] + "/blob/master/CHANGELOG.md"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(__dir__) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|benchmarks)/}) }
|
18
22
|
end
|
19
23
|
spec.bindir = "exe"
|
20
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
25
|
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.add_runtime_dependency "activesupport", ">= 3.1"
|
24
|
-
|
25
|
-
spec.add_development_dependency "bundler", "~> 1.12"
|
26
|
-
spec.add_development_dependency "rake", "~> 11.1"
|
27
|
-
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
-
spec.add_development_dependency "yard", "~> 0.9"
|
29
|
-
spec.add_development_dependency "benchmark-inputs", "~> 1.0"
|
30
26
|
end
|
data/lib/casual_support.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
require_relative "casual_support/version"
|
2
|
-
require_relative "casual_support/boolean"
|
3
|
-
require_relative "casual_support/comparable"
|
4
2
|
require_relative "casual_support/date"
|
5
3
|
require_relative "casual_support/enumerable"
|
6
4
|
require_relative "casual_support/hash"
|
7
|
-
require_relative "casual_support/integer"
|
8
|
-
require_relative "casual_support/numeric"
|
9
5
|
require_relative "casual_support/string"
|
10
6
|
require_relative "casual_support/struct"
|
11
7
|
require_relative "casual_support/time"
|
@@ -2,16 +2,16 @@ require_relative "../hash/putbang"
|
|
2
2
|
|
3
3
|
module Enumerable
|
4
4
|
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# Creates a Hash using the Enumerable's elements as keys, and using
|
6
|
+
# the given block to compute an associated value for each key.
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
# cache = id_list.index_to{|id| find_by_id(id) }
|
10
10
|
#
|
11
11
|
# @yield [key]
|
12
|
-
# @yieldparam key [
|
13
|
-
# @yieldreturn [
|
14
|
-
# @return [Hash
|
12
|
+
# @yieldparam key [Object]
|
13
|
+
# @yieldreturn [Object] value
|
14
|
+
# @return [Hash{key => value}]
|
15
15
|
def index_to()
|
16
16
|
self.reduce({}){|h, k| h.put!(k, (yield k)) }
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Hash
|
2
2
|
|
3
|
-
# Associates
|
4
|
-
# associated value. If
|
3
|
+
# Associates +key+ with +value+, and returns +key+'s previously
|
4
|
+
# associated value. If +key+ had no previously associated value,
|
5
5
|
# returns +Hash#default+.
|
6
6
|
#
|
7
7
|
# @example
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class Hash
|
2
2
|
|
3
|
-
# Associates
|
4
|
-
# the Hash instead of the value. Faster than +Hash#merge!+ for
|
5
|
-
#
|
3
|
+
# Associates +key+ with +value+. Similar to +Hash#[]=+, but returns
|
4
|
+
# the Hash instead of the value. Faster than +Hash#merge!+ for single
|
5
|
+
# updates in a loop.
|
6
6
|
#
|
7
7
|
# @example
|
8
8
|
# cache = id_list.reduce({}) do |hash, id|
|
@@ -3,10 +3,5 @@ require_relative "string/after_last"
|
|
3
3
|
require_relative "string/before"
|
4
4
|
require_relative "string/before_last"
|
5
5
|
require_relative "string/between"
|
6
|
-
require_relative "string/drop"
|
7
|
-
require_relative "string/first"
|
8
|
-
require_relative "string/from"
|
9
|
-
require_relative "string/last"
|
10
6
|
require_relative "string/prefix"
|
11
7
|
require_relative "string/suffix"
|
12
|
-
require_relative "string/to"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
# Searches for the first occurrence of
|
4
|
-
# portion of the String after that. If
|
3
|
+
# Searches for the first occurrence of +delimiter+, and returns the
|
4
|
+
# portion of the String after that. If +delimiter+ is not found,
|
5
5
|
# returns nil. Equivalent to <code>split(delimiter, 2).drop(1)[-1]</code>
|
6
6
|
# for non-empty delimiters.
|
7
7
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
# Searches for the last occurrence of
|
4
|
-
# portion of the String after that. If
|
3
|
+
# Searches for the last occurrence of +delimiter+, and returns the
|
4
|
+
# portion of the String after that. If +delimiter+ is not found,
|
5
5
|
# returns nil. Equivalent to <code>split(delimiter, -1).drop(1)[-1]</code>
|
6
6
|
# for non-empty delimiters.
|
7
7
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
# Searches for the first occurrence of
|
4
|
-
# portion of the String before that. If
|
3
|
+
# Searches for the first occurrence of +delimiter+, and returns the
|
4
|
+
# portion of the String before that. If +delimiter+ is not found,
|
5
5
|
# returns a copy of the original String. Equivalent to
|
6
6
|
# <code>split(delimiter, 2)[0]</code> for non-empty delimiters.
|
7
7
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
# Searches for the last occurrence of
|
4
|
-
# portion of the String before that. If
|
3
|
+
# Searches for the last occurrence of +delimiter+, and returns the
|
4
|
+
# portion of the String before that. If +delimiter+ is not found,
|
5
5
|
# returns a copy of the original String. Equivalent to
|
6
6
|
# <code>split(delimiter, -1)[0...-1].join(delimiter)</code> for
|
7
7
|
# existent delimiters.
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class String
|
2
2
|
|
3
3
|
# Returns the portion of the String between the first occurrences of
|
4
|
-
# an
|
5
|
-
# found, returns nil.
|
4
|
+
# an +open+ delimiter and a +close+ delimiter. If either delimiter is
|
5
|
+
# not found, returns nil.
|
6
6
|
#
|
7
7
|
# @example
|
8
8
|
# "i <b><3</b> ruby".between("<b>", "</b>") # == "<3"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
# Prepends
|
4
|
-
# start with
|
5
|
-
#
|
3
|
+
# Prepends +affix+ to the String only if the String does not already
|
4
|
+
# start with +affix+. Otherwise returns a duplicate of the String.
|
5
|
+
# Equivalent to +gsub(/^(?!affix)/, "affix")+.
|
6
6
|
#
|
7
7
|
# @example
|
8
8
|
# "example.com".prefix("www.") # == "www.example.com"
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class String
|
2
2
|
|
3
|
-
# Appends
|
4
|
-
# end with
|
3
|
+
# Appends +affix+ to the String only if the String does not already
|
4
|
+
# end with +affix+. Otherwise returns a duplicate of the String.
|
5
5
|
# Equivalent to +gsub(/(?<!affix)$/, "affix")+.
|
6
6
|
#
|
7
7
|
# @example
|
@@ -11,7 +11,7 @@ class Struct
|
|
11
11
|
#
|
12
12
|
# point.assign_attributes(y: 30, z: 50).to_h # == { x: 10, y: 30, z: 50 }
|
13
13
|
#
|
14
|
-
# @param new_attributes [Hash
|
14
|
+
# @param new_attributes [Hash{Symbol => Object}, Hash{String => Object}]
|
15
15
|
# @return [self]
|
16
16
|
def assign_attributes(new_attributes)
|
17
17
|
ms = self.members
|
@@ -3,9 +3,12 @@ require_relative "assign_attributes"
|
|
3
3
|
class Struct
|
4
4
|
|
5
5
|
# Constructs an instance of a subclass of Struct, and assigns the
|
6
|
-
# values of the given
|
7
|
-
#
|
8
|
-
#
|
6
|
+
# values of the given +attributes+ Hash to the instance.
|
7
|
+
#
|
8
|
+
# This method is intended for use only with subclasses of Struct which
|
9
|
+
# do not alter the default signature of the +initialize+ method.
|
10
|
+
# Specifically, the +initialize+ method must support invocation with
|
11
|
+
# no arguments.
|
9
12
|
#
|
10
13
|
# @see Struct#assign_attributes
|
11
14
|
#
|
@@ -14,7 +17,7 @@ class Struct
|
|
14
17
|
#
|
15
18
|
# Point.from_h(x: 10, y: 20, z: 30) # == Point.new(10, 20, 30)
|
16
19
|
#
|
17
|
-
# @param attributes [Hash
|
20
|
+
# @param attributes [Hash{Symbol => Object}, Hash{String => Object}]
|
18
21
|
# @return [Struct]
|
19
22
|
def self.from_h(attributes)
|
20
23
|
raise "Struct.from_h is for use only with subclasses of Struct" if self == Struct
|
metadata
CHANGED
@@ -1,102 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: casual_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.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:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: activesupport
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '3.1'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '3.1'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.12'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.12'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '11.1'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '11.1'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '5.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '5.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: yard
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0.9'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.9'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: benchmark-inputs
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.0'
|
11
|
+
date: 2020-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
97
13
|
description:
|
98
14
|
email:
|
99
|
-
- jonathan
|
15
|
+
- jonathan@hefner.pro
|
100
16
|
executables: []
|
101
17
|
extensions: []
|
102
18
|
extra_rdoc_files: []
|
@@ -110,11 +26,6 @@ files:
|
|
110
26
|
- Rakefile
|
111
27
|
- casual_support.gemspec
|
112
28
|
- lib/casual_support.rb
|
113
|
-
- lib/casual_support/boolean.rb
|
114
|
-
- lib/casual_support/boolean/to_z.rb
|
115
|
-
- lib/casual_support/comparable.rb
|
116
|
-
- lib/casual_support/comparable/at_least.rb
|
117
|
-
- lib/casual_support/comparable/at_most.rb
|
118
29
|
- lib/casual_support/date.rb
|
119
30
|
- lib/casual_support/date/to_hms.rb
|
120
31
|
- lib/casual_support/date/to_ymd.rb
|
@@ -124,23 +35,14 @@ files:
|
|
124
35
|
- lib/casual_support/hash.rb
|
125
36
|
- lib/casual_support/hash/displace.rb
|
126
37
|
- lib/casual_support/hash/putbang.rb
|
127
|
-
- lib/casual_support/integer.rb
|
128
|
-
- lib/casual_support/integer/to_hex.rb
|
129
|
-
- lib/casual_support/numeric.rb
|
130
|
-
- lib/casual_support/numeric/sign.rb
|
131
38
|
- lib/casual_support/string.rb
|
132
39
|
- lib/casual_support/string/after.rb
|
133
40
|
- lib/casual_support/string/after_last.rb
|
134
41
|
- lib/casual_support/string/before.rb
|
135
42
|
- lib/casual_support/string/before_last.rb
|
136
43
|
- lib/casual_support/string/between.rb
|
137
|
-
- lib/casual_support/string/drop.rb
|
138
|
-
- lib/casual_support/string/first.rb
|
139
|
-
- lib/casual_support/string/from.rb
|
140
|
-
- lib/casual_support/string/last.rb
|
141
44
|
- lib/casual_support/string/prefix.rb
|
142
45
|
- lib/casual_support/string/suffix.rb
|
143
|
-
- lib/casual_support/string/to.rb
|
144
46
|
- lib/casual_support/struct.rb
|
145
47
|
- lib/casual_support/struct/assign_attributes.rb
|
146
48
|
- lib/casual_support/struct/from_h.rb
|
@@ -151,7 +53,10 @@ files:
|
|
151
53
|
homepage: https://github.com/jonathanhefner/casual_support
|
152
54
|
licenses:
|
153
55
|
- MIT
|
154
|
-
metadata:
|
56
|
+
metadata:
|
57
|
+
homepage_uri: https://github.com/jonathanhefner/casual_support
|
58
|
+
source_code_uri: https://github.com/jonathanhefner/casual_support
|
59
|
+
changelog_uri: https://github.com/jonathanhefner/casual_support/blob/master/CHANGELOG.md
|
155
60
|
post_install_message:
|
156
61
|
rdoc_options: []
|
157
62
|
require_paths:
|
@@ -160,14 +65,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
65
|
requirements:
|
161
66
|
- - ">="
|
162
67
|
- !ruby/object:Gem::Version
|
163
|
-
version: '
|
68
|
+
version: '2.6'
|
164
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
70
|
requirements:
|
166
71
|
- - ">="
|
167
72
|
- !ruby/object:Gem::Version
|
168
73
|
version: '0'
|
169
74
|
requirements: []
|
170
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.1.2
|
171
76
|
signing_key:
|
172
77
|
specification_version: 4
|
173
78
|
summary: Utility extensions to core objects, a la Active Support
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative "boolean/to_z"
|
@@ -1,22 +0,0 @@
|
|
1
|
-
class FalseClass
|
2
|
-
|
3
|
-
# Returns 0 if +false+, 1 if +true+.
|
4
|
-
#
|
5
|
-
# @return [Integer]
|
6
|
-
def to_z
|
7
|
-
0
|
8
|
-
end
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
|
13
|
-
class TrueClass
|
14
|
-
|
15
|
-
# Returns 0 if +false+, 1 if +true+.
|
16
|
-
#
|
17
|
-
# @return [Integer]
|
18
|
-
def to_z
|
19
|
-
1
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Comparable
|
2
|
-
|
3
|
-
# Enforces a lower bound for the value.
|
4
|
-
#
|
5
|
-
# @example
|
6
|
-
# -10.at_least(0) # == 0
|
7
|
-
# 99.at_least(0) # == 99
|
8
|
-
#
|
9
|
-
# @param limit [Comparable]
|
10
|
-
# @return [Comparable]
|
11
|
-
def at_least(limit)
|
12
|
-
self < limit ? limit : self
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Comparable
|
2
|
-
|
3
|
-
# Enforces an upper bound for the value.
|
4
|
-
#
|
5
|
-
# @example
|
6
|
-
# 120.at_most(100) # == 100
|
7
|
-
# 90.at_most(100) # == 90
|
8
|
-
#
|
9
|
-
# @param limit [Comparable]
|
10
|
-
# @return [Comparable]
|
11
|
-
def at_most(limit)
|
12
|
-
self > limit ? limit : self
|
13
|
-
end
|
14
|
-
|
15
|
-
alias_method :cap, :at_most
|
16
|
-
|
17
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative "integer/to_hex"
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Integer
|
4
|
-
|
5
|
-
# Formats the Integer as a zero-padded lower-case hexadecimal string.
|
6
|
-
# If the length of the raw hexadecimal string exceeds the desired
|
7
|
-
# width, the string will be returned as-is (without padding or
|
8
|
-
# truncation).
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# 250.to_hex # == "fa"
|
12
|
-
# 250.to_hex(4) # == "00fa"
|
13
|
-
# 250.to_hex(1) # == "fa"
|
14
|
-
#
|
15
|
-
# @param width [Integer]
|
16
|
-
# @return [String]
|
17
|
-
def to_hex(width = 0)
|
18
|
-
width > 1 ? self.to_s(16).rjust(width, "0") : self.to_s(16)
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require_relative "numeric/sign"
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class String
|
2
|
-
|
3
|
-
# Drops characters from the beginning of the String, and returns the
|
4
|
-
# remainder. If the number of characters to drop is greater than the
|
5
|
-
# length of the String, an empty string is returned.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# "abcdef".drop(0) # == "abcdef"
|
9
|
-
# "abcdef".drop(3) # == "def"
|
10
|
-
# "abcdef".drop(6) # == ""
|
11
|
-
# "abcdef".drop(7) # == ""
|
12
|
-
#
|
13
|
-
# @param n [Integer]
|
14
|
-
# @return [String]
|
15
|
-
def drop(n)
|
16
|
-
return self.dup if n <= 0
|
17
|
-
self[n, self.length] || ""
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/access"
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
remove_method :first
|
6
|
-
|
7
|
-
# Returns the first +limit+ characters from the beginning of the
|
8
|
-
# String.
|
9
|
-
#
|
10
|
-
# This method replaces Active Support's +String#first+. However, it
|
11
|
-
# returns an empty string when given a negative +limit+, whereas
|
12
|
-
# Active Support 6.0 and previous remove +limit.abs+ characters from
|
13
|
-
# the end of the String. Returning an empty string is more intuitive
|
14
|
-
# behavior if +first+ is interpreted as "keep up to +limit+
|
15
|
-
# characters." (At most, a negative +limit+ should *keep* +limit.abs+
|
16
|
-
# characters from the end of the String, instead of *remove* that many
|
17
|
-
# characters, but returning an empty string is a conservative
|
18
|
-
# compromise.) This method is also faster than Active Support's
|
19
|
-
# implementation.
|
20
|
-
#
|
21
|
-
# @example
|
22
|
-
# "abcdef".first(0) # == ""
|
23
|
-
# "abcdef".first(3) # == "abc"
|
24
|
-
# "abcdef".first(6) # == "abcdef"
|
25
|
-
# "abcdef".first(7) # == "abcdef"
|
26
|
-
# "abcdef".first(-1) # == ""
|
27
|
-
#
|
28
|
-
# @param limit [Integer]
|
29
|
-
# @return [String]
|
30
|
-
def first(limit = 1)
|
31
|
-
self[0, limit] || ""
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/access"
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
remove_method :from
|
6
|
-
|
7
|
-
# Returns the substring starting at a given position, spanning through
|
8
|
-
# the end of the String.
|
9
|
-
#
|
10
|
-
# This method replaces Active Support's +String#from+. It is faster.
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# "abcdef".from(0) # == "abcdef"
|
14
|
-
# "abcdef".from(3) # == "def"
|
15
|
-
# "abcdef".from(6) # == ""
|
16
|
-
# "abcdef".from(7) # == ""
|
17
|
-
#
|
18
|
-
# @param position [Integer]
|
19
|
-
# @return [String]
|
20
|
-
def from(position)
|
21
|
-
self[position, self.length]
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/access"
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
remove_method :last
|
6
|
-
|
7
|
-
# Returns the last +limit+ characters from the end of the String.
|
8
|
-
#
|
9
|
-
# This method replaces Active Support's +String#last+. However, it
|
10
|
-
# returns an empty string when given a negative +limit+, whereas
|
11
|
-
# Active Support 6.0 and previous remove +limit.abs+ characters from
|
12
|
-
# the beginning of the String. Returning an empty string is more
|
13
|
-
# intuitive behavior if +last+ is interpreted as "keep up to +limit+
|
14
|
-
# characters." (At most, a negative +limit+ should *keep* +limit.abs+
|
15
|
-
# characters from the beginning of the String, instead of *remove*
|
16
|
-
# that many characters, but returning an empty string is a
|
17
|
-
# conservative compromise.) This method is also faster than Active
|
18
|
-
# Support's implementation.
|
19
|
-
#
|
20
|
-
# @example
|
21
|
-
# "abcdef".last(0) # == ""
|
22
|
-
# "abcdef".last(3) # == "def"
|
23
|
-
# "abcdef".last(6) # == "abcdef"
|
24
|
-
# "abcdef".last(7) # == "abcdef"
|
25
|
-
# "abcdef".last(-1) # == ""
|
26
|
-
#
|
27
|
-
# @param limit [Integer]
|
28
|
-
# @return [String]
|
29
|
-
def last(limit = 1)
|
30
|
-
self[[length - limit, 0].max, limit] || ""
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/access"
|
2
|
-
|
3
|
-
class String
|
4
|
-
|
5
|
-
remove_method :to
|
6
|
-
|
7
|
-
# Returns the substring from the start of the String, spanning through
|
8
|
-
# a given position.
|
9
|
-
#
|
10
|
-
# This method replaces Active Support's +String#to+. It is faster.
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# "abcdef".to(0) # == "a"
|
14
|
-
# "abcdef".to(2) # == "abc"
|
15
|
-
# "abcdef".to(5) # == "abcdef"
|
16
|
-
# "abcdef".to(6) # == "abcdef"
|
17
|
-
#
|
18
|
-
# @param position [Integer]
|
19
|
-
# @return [String]
|
20
|
-
def to(position)
|
21
|
-
position += self.length if position < 0
|
22
|
-
self[0, position + 1] || ""
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|