casual_support 3.0.2 → 5.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -3
  3. data/Gemfile +4 -1
  4. data/README.md +15 -67
  5. data/Rakefile +0 -13
  6. data/casual_support.gemspec +10 -15
  7. data/lib/casual_support/enumerable.rb +0 -1
  8. data/lib/casual_support/string/after.rb +2 -2
  9. data/lib/casual_support/string/after_last.rb +2 -2
  10. data/lib/casual_support/string/before.rb +2 -2
  11. data/lib/casual_support/string/before_last.rb +2 -2
  12. data/lib/casual_support/string/between.rb +2 -2
  13. data/lib/casual_support/string/prefix.rb +3 -3
  14. data/lib/casual_support/string/suffix.rb +2 -2
  15. data/lib/casual_support/string.rb +0 -5
  16. data/lib/casual_support/version.rb +1 -1
  17. data/lib/casual_support.rb +0 -8
  18. metadata +9 -124
  19. data/.gitignore +0 -10
  20. data/.travis.yml +0 -5
  21. data/lib/casual_support/boolean/to_z.rb +0 -22
  22. data/lib/casual_support/boolean.rb +0 -1
  23. data/lib/casual_support/comparable/at_least.rb +0 -15
  24. data/lib/casual_support/comparable/at_most.rb +0 -17
  25. data/lib/casual_support/comparable.rb +0 -2
  26. data/lib/casual_support/date/to_hms.rb +0 -15
  27. data/lib/casual_support/date/to_ymd.rb +0 -13
  28. data/lib/casual_support/date.rb +0 -2
  29. data/lib/casual_support/enumerable/index_to.rb +0 -19
  30. data/lib/casual_support/hash/displace.rb +0 -26
  31. data/lib/casual_support/hash/putbang.rb +0 -20
  32. data/lib/casual_support/hash.rb +0 -2
  33. data/lib/casual_support/integer/to_hex.rb +0 -21
  34. data/lib/casual_support/integer.rb +0 -1
  35. data/lib/casual_support/numeric/sign.rb +0 -15
  36. data/lib/casual_support/numeric.rb +0 -1
  37. data/lib/casual_support/string/drop.rb +0 -20
  38. data/lib/casual_support/string/first.rb +0 -34
  39. data/lib/casual_support/string/from.rb +0 -24
  40. data/lib/casual_support/string/last.rb +0 -33
  41. data/lib/casual_support/string/to.rb +0 -25
  42. data/lib/casual_support/struct/assign_attributes.rb +0 -25
  43. data/lib/casual_support/struct/from_h.rb +0 -24
  44. data/lib/casual_support/struct.rb +0 -2
  45. data/lib/casual_support/time/to_hms.rb +0 -19
  46. data/lib/casual_support/time/to_ymd.rb +0 -19
  47. data/lib/casual_support/time.rb +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3530a25d5599a70b7b6d84c2eb83373573f09a38f0b7d071a04ea9820858eb9
4
- data.tar.gz: acc967bb9e7a8242883be4dbadb242cda75a961b43abdbe337c06bf9b4ceb3a6
3
+ metadata.gz: b1b6de67e75bbf7aa49d6b57e04fe896aee7514eda1a9a13c24849ccbf21efce
4
+ data.tar.gz: 9a4eb5b9a69f7935a2e3910b22caaf3cf75550c0cf092f86bfce72af29f10eff
5
5
  SHA512:
6
- metadata.gz: 1a9e64d89fd2b3c920c93ecb186d3d8da6e1e7fed622bf8e9a8d85b420d63b3b0dc92b770cdff3220c6ab250af7642b9f99c634312a5f8bc45a484c2e186b29d
7
- data.tar.gz: 5b1e4c16151b2f829315c150709cda75a17f6ba316ea73338db7df4eef2599d6f3643815b5dcc6e070c03d1e1883c4be591e81377ba01fcbdbbe57fc4c6a2a82
6
+ metadata.gz: 93f4a01af09b19777acb8159c33f5baf8bcd1c50763b315725794579d465feb0291a9aae2df97e086b9a44b71003ef45f9149aa0980d72d1c6a7dd67eecdfa27
7
+ data.tar.gz: 5cefb130b0e143798a37ad642b06e23a96d74ed66a351d1fbee89b322338684ea0addce22b298721a70729100a13037e6c28f971d8389858831043040e48ac74
data/CHANGELOG.md CHANGED
@@ -1,3 +1,42 @@
1
+ ## 5.0.0
2
+
3
+ * [BREAKING] Drop support for Ruby < 3.4
4
+ * [BREAKING] Remove `Hash#put!`
5
+ * Use `hash.merge!(key => value)` instead
6
+ * [BREAKING] Remove `Hash#displace`
7
+ * [BREAKING] Remove `Struct.from_h`
8
+ * In Ruby 3.2+, call the generated struct class's constructor with
9
+ keyword arguments instead: `Point.new(x: 1, y: 2, z: 3)`
10
+ * [BREAKING] Remove `Struct#assign_attributes`
11
+ * [BREAKING] Remove `Enumerable#index_to`
12
+ * Use Active Support's `Enumerable#index_with` instead
13
+ * [BREAKING] Remove `Date#to_hms`
14
+ * [BREAKING] Remove `Date#to_ymd`
15
+ * Use `date.to_s` instead
16
+ * [BREAKING] Remove `Time#to_hms`
17
+ * Use `time.strftime("%H:%M:%S")` instead
18
+ * [BREAKING] Remove `Time#to_ymd`
19
+ * Use `time.to_date.to_s` or `time.strftime("%Y-%m-%d")` instead
20
+
21
+
22
+ ## 4.0.0
23
+
24
+ * [BREAKING] Drop support for Ruby < 2.6
25
+ * [BREAKING] Remove `String#first` and `String#last`
26
+ * Remove `String#to` and `String#from`
27
+ * Remove Active Support dependency
28
+ * [BREAKING] Remove `String#drop`
29
+ * Use `string[n..]` instead
30
+ * [BREAKING] Remove `Comparable#at_least` and `Comparable#at_most`
31
+ * Use `value.clamp(limit..)` and `value.clamp(..limit)` instead
32
+ * [BREAKING] Remove `Integer#to_hex`
33
+ * Use `("%0#{width}x" % int)` instead
34
+ * [BREAKING] Remove `Numeric#sign`
35
+ * Use `(num <=> 0)` instead
36
+ * [BREAKING] Remove `Boolean#to_z`
37
+ * Use `(bool ? 1 : 0)` instead
38
+
39
+
1
40
  ## 3.0.2
2
41
 
3
42
  * Add `Date#to_hms` dummy method
@@ -13,9 +52,10 @@
13
52
  ## 3.0.0
14
53
 
15
54
  * [BREAKING] Remove block param from `Enumerable#duplicates`
16
- * [BREAKING] Remove `Comparable#clamp`. (Native in Ruby 2.4.)
17
- * [BREAKING] Remove `String#lchomp`. (Native in Ruby 2.5 as
18
- `String#delete_prefix`.)
55
+ * [BREAKING] Remove `Comparable#clamp`
56
+ * Native in Ruby 2.4
57
+ * [BREAKING] Remove `String#lchomp`
58
+ * Native in Ruby 2.5 as `String#delete_prefix`
19
59
  * Add `Numeric#sign`
20
60
  * Add `Boolean#to_z`
21
61
  * Add `Hash#displace`
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in casual_support.gemspec
4
4
  gemspec
5
+
6
+ gem "rake", "~> 13.0"
7
+ gem "minitest", "~> 6.0"
data/README.md CHANGED
@@ -1,82 +1,30 @@
1
1
  # casual_support
2
2
 
3
- Utility methods as extensions to Ruby core objects, a la Active Support.
3
+ Utility methods as extensions to core Ruby objects, a la
4
+ [Active Support](https://guides.rubyonrails.org/active_support_core_extensions.html).
4
5
 
5
- Also a nod to the epic [Facets] library, which has a vast quantity and
6
- wide variety of utility functions. *casual_support* distinguishes
7
- itself in a few ways:
8
6
 
9
- - Focus on fast implementations. See the benchmarks directory for
10
- performance comparisons with typical and alternative implementations.
11
- - Low memory footprint without required cherry-picking. Cherry-picking
12
- is still possible though!
13
- - Intended to be used alongside Active Support. Does not clash with
14
- Active Support methods, and overrides only a few to provide more
15
- performant implementations.
16
-
17
- [Facets]: https://github.com/rubyworks/facets
18
-
19
-
20
- ## Utility Methods
21
-
22
- - Boolean
23
- - [#to_z](http://www.rubydoc.info/gems/casual_support/TrueClass:to_z)
24
- - [Comparable](http://www.rubydoc.info/gems/casual_support/Comparable)
25
- - [#at_least](http://www.rubydoc.info/gems/casual_support/Comparable:at_least)
26
- - [#at_most](http://www.rubydoc.info/gems/casual_support/Comparable:at_most)
27
- - [Date](http://www.rubydoc.info/gems/casual_support/Date)
28
- - [#to_hms](http://www.rubydoc.info/gems/casual_support/Date:to_hms)
29
- - [#to_ymd](http://www.rubydoc.info/gems/casual_support/Date:to_ymd)
30
- - [Enumerable](http://www.rubydoc.info/gems/casual_support/Enumerable)
31
- - [#duplicates](http://www.rubydoc.info/gems/casual_support/Enumerable:duplicates)
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)
7
+ ## API
59
8
 
9
+ - [`Enumerable`](https://www.rubydoc.info/gems/casual_support/Enumerable)
10
+ - [`#duplicates`](https://www.rubydoc.info/gems/casual_support/Enumerable:duplicates)
11
+ - [`String`](https://www.rubydoc.info/gems/casual_support/String)
12
+ - [`#after`](https://www.rubydoc.info/gems/casual_support/String:after)
13
+ - [`#after_last`](https://www.rubydoc.info/gems/casual_support/String:after_last)
14
+ - [`#before`](https://www.rubydoc.info/gems/casual_support/String:before)
15
+ - [`#before_last`](https://www.rubydoc.info/gems/casual_support/String:before_last)
16
+ - [`#between`](https://www.rubydoc.info/gems/casual_support/String:between)
17
+ - [`#prefix`](https://www.rubydoc.info/gems/casual_support/String:prefix)
18
+ - [`#suffix`](https://www.rubydoc.info/gems/casual_support/String:suffix)
60
19
 
61
20
  ## Installation
62
21
 
63
- Install from [Ruby Gems](https://rubygems.org/gems/casual_support):
64
-
65
- ```bash
66
- $ gem install casual_support
67
- ```
68
-
69
- Then require in your Ruby script:
70
-
71
- ```ruby
72
- require "casual_support"
73
- ```
22
+ Install the [`casual_support` gem](https://rubygems.org/gems/casual_support).
74
23
 
75
24
 
76
25
  ## Contributing
77
26
 
78
- Run `rake test` to run the tests. You can also run `rake irb` for an
79
- interactive prompt that pre-loads the project code.
27
+ Run `rake test` to run the tests.
80
28
 
81
29
 
82
30
  ## 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"
@@ -1,30 +1,25 @@
1
- # coding: utf-8
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.hefner@gmail.com"]
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 = ">= 3.4"
15
13
 
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features|benchmarks)/})
14
+ spec.metadata["source_code_uri"] = spec.homepage
15
+ spec.metadata["changelog_uri"] = spec.metadata["source_code_uri"] + "/blob/master/CHANGELOG.md"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(__dir__) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.start_with?("test/", ".git") }
18
21
  end
19
22
  spec.bindir = "exe"
20
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
24
  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
25
  end
@@ -1,2 +1 @@
1
1
  require_relative "enumerable/duplicates"
2
- require_relative "enumerable/index_to"
@@ -1,7 +1,7 @@
1
1
  class String
2
2
 
3
- # Searches for the first occurrence of a delimiter, and returns the
4
- # portion of the String after that. If the delimiter is not found,
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 a delimiter, and returns the
4
- # portion of the String after that. If the delimiter is not found,
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 a delimiter, and returns the
4
- # portion of the String before that. If the delimiter is not found,
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 a delimiter, and returns the
4
- # portion of the String before that. If the delimiter is not found,
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 opening and a closing delimiter. If either delimiter is not
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 a prefix to the String only if the String does not already
4
- # start with that prefix. Otherwise returns a duplicate of the
5
- # String. Equivalent to +gsub(/^(?!prefix)/, "prefix")+.
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 a suffix to the String only if the String does not already
4
- # end with that suffix. Otherwise returns a duplicate of the String.
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
@@ -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,3 +1,3 @@
1
1
  module CasualSupport
2
- VERSION = "3.0.2"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -1,11 +1,3 @@
1
1
  require_relative "casual_support/version"
2
- require_relative "casual_support/boolean"
3
- require_relative "casual_support/comparable"
4
- require_relative "casual_support/date"
5
2
  require_relative "casual_support/enumerable"
6
- require_relative "casual_support/hash"
7
- require_relative "casual_support/integer"
8
- require_relative "casual_support/numeric"
9
3
  require_relative "casual_support/string"
10
- require_relative "casual_support/struct"
11
- require_relative "casual_support/time"
metadata CHANGED
@@ -1,108 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casual_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Hefner
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2019-07-04 00:00:00.000000000 Z
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'
97
- description:
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
98
12
  email:
99
- - jonathan.hefner@gmail.com
13
+ - jonathan@hefner.pro
100
14
  executables: []
101
15
  extensions: []
102
16
  extra_rdoc_files: []
103
17
  files:
104
- - ".gitignore"
105
- - ".travis.yml"
106
18
  - CHANGELOG.md
107
19
  - Gemfile
108
20
  - LICENSE.txt
@@ -110,49 +22,23 @@ files:
110
22
  - Rakefile
111
23
  - casual_support.gemspec
112
24
  - 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
- - lib/casual_support/date.rb
119
- - lib/casual_support/date/to_hms.rb
120
- - lib/casual_support/date/to_ymd.rb
121
25
  - lib/casual_support/enumerable.rb
122
26
  - lib/casual_support/enumerable/duplicates.rb
123
- - lib/casual_support/enumerable/index_to.rb
124
- - lib/casual_support/hash.rb
125
- - lib/casual_support/hash/displace.rb
126
- - 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
27
  - lib/casual_support/string.rb
132
28
  - lib/casual_support/string/after.rb
133
29
  - lib/casual_support/string/after_last.rb
134
30
  - lib/casual_support/string/before.rb
135
31
  - lib/casual_support/string/before_last.rb
136
32
  - 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
33
  - lib/casual_support/string/prefix.rb
142
34
  - lib/casual_support/string/suffix.rb
143
- - lib/casual_support/string/to.rb
144
- - lib/casual_support/struct.rb
145
- - lib/casual_support/struct/assign_attributes.rb
146
- - lib/casual_support/struct/from_h.rb
147
- - lib/casual_support/time.rb
148
- - lib/casual_support/time/to_hms.rb
149
- - lib/casual_support/time/to_ymd.rb
150
35
  - lib/casual_support/version.rb
151
36
  homepage: https://github.com/jonathanhefner/casual_support
152
37
  licenses:
153
38
  - MIT
154
- metadata: {}
155
- post_install_message:
39
+ metadata:
40
+ source_code_uri: https://github.com/jonathanhefner/casual_support
41
+ changelog_uri: https://github.com/jonathanhefner/casual_support/blob/master/CHANGELOG.md
156
42
  rdoc_options: []
157
43
  require_paths:
158
44
  - lib
@@ -160,15 +46,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
46
  requirements:
161
47
  - - ">="
162
48
  - !ruby/object:Gem::Version
163
- version: '0'
49
+ version: '3.4'
164
50
  required_rubygems_version: !ruby/object:Gem::Requirement
165
51
  requirements:
166
52
  - - ">="
167
53
  - !ruby/object:Gem::Version
168
54
  version: '0'
169
55
  requirements: []
170
- rubygems_version: 3.0.1
171
- signing_key:
56
+ rubygems_version: 4.0.10
172
57
  specification_version: 4
173
58
  summary: Utility extensions to core objects, a la Active Support
174
59
  test_files: []
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.gem
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.2.4
5
- before_install: gem install bundler -v 1.12.3
@@ -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 +0,0 @@
1
- require_relative "boolean/to_z"
@@ -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,2 +0,0 @@
1
- require_relative "comparable/at_least"
2
- require_relative "comparable/at_most"
@@ -1,15 +0,0 @@
1
- require "date"
2
-
3
-
4
- class Date
5
-
6
- # Returns "00:00:00".
7
- #
8
- # Provided for parity with {Time#to_hms}.
9
- #
10
- # @return [String]
11
- def to_hms
12
- "00:00:00"
13
- end
14
-
15
- end
@@ -1,13 +0,0 @@
1
- require "date"
2
-
3
-
4
- class Date
5
-
6
- # Alias of +Date#to_s+. Formats the Date as "YYYY-MM-DD".
7
- #
8
- # Provided for parity with {Time#to_hms}.
9
- #
10
- # @return [String]
11
- alias :to_ymd :to_s
12
-
13
- end
@@ -1,2 +0,0 @@
1
- require_relative "date/to_hms"
2
- require_relative "date/to_ymd"
@@ -1,19 +0,0 @@
1
- require_relative "../hash/putbang"
2
-
3
- module Enumerable
4
-
5
- # Converts the Enumerable into a Hash, using its elements as keys and
6
- # using the given block to compute an associated value for each key.
7
- #
8
- # @example
9
- # cache = id_list.index_to{|id| find_by_id(id) }
10
- #
11
- # @yield [key]
12
- # @yieldparam key ['K]
13
- # @yieldreturn ['V]
14
- # @return [Hash<'K, 'V>]
15
- def index_to()
16
- self.reduce({}){|h, k| h.put!(k, (yield k)) }
17
- end
18
-
19
- end
@@ -1,26 +0,0 @@
1
- class Hash
2
-
3
- # Associates a key with a value, and returns the key's previously
4
- # associated value. If the key had no previously associated value,
5
- # returns +Hash#default+.
6
- #
7
- # @example
8
- # visited = { "id1" => true, "id2" => false }
9
- #
10
- # visited.displace("id1", true) # == true
11
- # visited # == { "id1" => true, "id2" => false }
12
- # visited.displace("id2", true) # == false
13
- # visited # == { "id1" => true, "id2" => true }
14
- # visited.displace("id3", true) # == nil
15
- # visited # == { "id1" => true, "id2" => true, "id3" => true }
16
- #
17
- # @param key
18
- # @param value
19
- # @return [Hash]
20
- def displace(key, value)
21
- old_value = self[key]
22
- self[key] = value
23
- old_value
24
- end
25
-
26
- end
@@ -1,20 +0,0 @@
1
- class Hash
2
-
3
- # Associates a key with a value. Similar to +Hash#[]=+, but returns
4
- # the Hash instead of the value. Faster than +Hash#merge!+ for
5
- # singular values in a loop.
6
- #
7
- # @example
8
- # cache = id_list.reduce({}) do |hash, id|
9
- # hash.put!(id, find_by_id(id))
10
- # end
11
- #
12
- # @param key
13
- # @param value
14
- # @return [Hash]
15
- def put!(key, value)
16
- self[key] = value
17
- self
18
- end
19
-
20
- end
@@ -1,2 +0,0 @@
1
- require_relative "hash/displace"
2
- require_relative "hash/putbang"
@@ -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 "integer/to_hex"
@@ -1,15 +0,0 @@
1
- class Numeric
2
-
3
- # Returns the sign of the number expressed as +-1+, +0+, or +1+.
4
- #
5
- # @example
6
- # -4.sign # == -1
7
- # 0.sign # == 0
8
- # 16.sign # == 1
9
- #
10
- # @return [Integer]
11
- def sign
12
- self <=> 0
13
- end
14
-
15
- 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
@@ -1,25 +0,0 @@
1
- class Struct
2
-
3
- # Assigns values in the given Hash to corresponding attributes of the
4
- # Struct. Both Symbol keys and String keys are accepted. Keys which
5
- # don't correspond to an attribute of the Struct are ignored. Mutates
6
- # the Struct and returns it.
7
- #
8
- # @example
9
- # Point = Struct.new(:x, :y, :z)
10
- # point = Point.new(10, 20, 30)
11
- #
12
- # point.assign_attributes(y: 30, z: 50).to_h # == { x: 10, y: 30, z: 50 }
13
- #
14
- # @param new_attributes [Hash<Symbol, Object>, Hash<String, Object>]
15
- # @return [self]
16
- def assign_attributes(new_attributes)
17
- ms = self.members
18
- new_attributes.each do |k, v|
19
- m = k.to_sym
20
- self[m] = v if ms.include?(m)
21
- end
22
- self
23
- end
24
-
25
- end
@@ -1,24 +0,0 @@
1
- require_relative "assign_attributes"
2
-
3
- class Struct
4
-
5
- # Constructs an instance of a subclass of Struct, and assigns the
6
- # values of the given attribute Hash to the instance. This method is
7
- # intended for use only with subclasses of Struct which do not alter
8
- # the default signature of the +initialize+ method.
9
- #
10
- # @see Struct#assign_attributes
11
- #
12
- # @example
13
- # Point = Struct.new(:x, :y, :z)
14
- #
15
- # Point.from_h(x: 10, y: 20, z: 30) # == Point.new(10, 20, 30)
16
- #
17
- # @param attributes [Hash<Symbol, Object>, Hash<String, Object>]
18
- # @return [Struct]
19
- def self.from_h(attributes)
20
- raise "Struct.from_h is for use only with subclasses of Struct" if self == Struct
21
- self.new.assign_attributes(attributes)
22
- end
23
-
24
- end
@@ -1,2 +0,0 @@
1
- require_relative "struct/assign_attributes"
2
- require_relative "struct/from_h"
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Time
4
-
5
- # Formats the Time as "HH:MM:SS". Equivalent to
6
- # +strftime("%H:%M:%S")+, but faster.
7
- #
8
- # @example
9
- # Time.new(1999, 12, 31, 23, 59, 59).to_hms # == "23:59:59"
10
- #
11
- # @return [String]
12
- def to_hms
13
- # Date#strftime appears to be **much** faster than Time#strftime
14
- # (nearly 3x faster!). If Time#strftime becomes optimized to that
15
- # level in the future, it should be used instead of sprintf.
16
- sprintf("%02d:%02d:%02d", hour, min, sec)
17
- end
18
-
19
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Time
4
-
5
- # Formats the Time as "YYYY-MM-DD". Equivalent to
6
- # +strftime("%Y-%m-%d")+, but faster.
7
- #
8
- # @example
9
- # Time.new(1999, 12, 31, 23, 59, 59).to_ymd # == "1999-12-31"
10
- #
11
- # @return [String]
12
- def to_ymd
13
- # Date#strftime appears to be **much** faster than Time#strftime
14
- # (nearly 3x faster!). If Time#strftime becomes optimized to that
15
- # level in the future, it should be used instead of sprintf.
16
- sprintf("%04d-%02d-%02d", year, month, day)
17
- end
18
-
19
- end
@@ -1,2 +0,0 @@
1
- require_relative "time/to_hms"
2
- require_relative "time/to_ymd"