casual_support 3.0.2 → 4.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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +22 -3
  5. data/Gemfile +5 -1
  6. data/README.md +34 -62
  7. data/Rakefile +0 -13
  8. data/casual_support.gemspec +11 -15
  9. data/lib/casual_support.rb +0 -4
  10. data/lib/casual_support/date/to_ymd.rb +1 -1
  11. data/lib/casual_support/enumerable/index_to.rb +5 -5
  12. data/lib/casual_support/hash/displace.rb +2 -2
  13. data/lib/casual_support/hash/putbang.rb +3 -3
  14. data/lib/casual_support/string.rb +0 -5
  15. data/lib/casual_support/string/after.rb +2 -2
  16. data/lib/casual_support/string/after_last.rb +2 -2
  17. data/lib/casual_support/string/before.rb +2 -2
  18. data/lib/casual_support/string/before_last.rb +2 -2
  19. data/lib/casual_support/string/between.rb +2 -2
  20. data/lib/casual_support/string/prefix.rb +3 -3
  21. data/lib/casual_support/string/suffix.rb +2 -2
  22. data/lib/casual_support/struct/assign_attributes.rb +1 -1
  23. data/lib/casual_support/struct/from_h.rb +7 -4
  24. data/lib/casual_support/version.rb +1 -1
  25. metadata +10 -105
  26. data/lib/casual_support/boolean.rb +0 -1
  27. data/lib/casual_support/boolean/to_z.rb +0 -22
  28. data/lib/casual_support/comparable.rb +0 -2
  29. data/lib/casual_support/comparable/at_least.rb +0 -15
  30. data/lib/casual_support/comparable/at_most.rb +0 -17
  31. data/lib/casual_support/integer.rb +0 -1
  32. data/lib/casual_support/integer/to_hex.rb +0 -21
  33. data/lib/casual_support/numeric.rb +0 -1
  34. data/lib/casual_support/numeric/sign.rb +0 -15
  35. data/lib/casual_support/string/drop.rb +0 -20
  36. data/lib/casual_support/string/first.rb +0 -34
  37. data/lib/casual_support/string/from.rb +0 -24
  38. data/lib/casual_support/string/last.rb +0 -33
  39. data/lib/casual_support/string/to.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3530a25d5599a70b7b6d84c2eb83373573f09a38f0b7d071a04ea9820858eb9
4
- data.tar.gz: acc967bb9e7a8242883be4dbadb242cda75a961b43abdbe337c06bf9b4ceb3a6
3
+ metadata.gz: f0b92ba05be9a6f0ad71a911c435c78d450f06c094108e07b9bad99bc87ae512
4
+ data.tar.gz: 893f5f3e708acd70741c6fd688463aad826f1eacd426bd48ec7b30c820ac8768
5
5
  SHA512:
6
- metadata.gz: 1a9e64d89fd2b3c920c93ecb186d3d8da6e1e7fed622bf8e9a8d85b420d63b3b0dc92b770cdff3220c6ab250af7642b9f99c634312a5f8bc45a484c2e186b29d
7
- data.tar.gz: 5b1e4c16151b2f829315c150709cda75a17f6ba316ea73338db7df4eef2599d6f3643815b5dcc6e070c03d1e1883c4be591e81377ba01fcbdbbe57fc4c6a2a82
6
+ metadata.gz: 944da5f33d43a08cc3af8649123b8577e3c4fe504584c86d5aa31afd514c5a9112af504c8aca204f11a08c7ae078d3d9f9c6125dfaf8a3e45c6f2e80fa98d70f
7
+ data.tar.gz: 2b6af778597dc30e0bb378d402c5a5c4504b4064b1f44bdcc38ba6a57014bd2bf74ff529579808d62d05ce5151717a6fa9bea18f600d2560f904ab545a5b63c2
data/.gitignore CHANGED
@@ -4,7 +4,7 @@
4
4
  /_yardoc/
5
5
  /coverage/
6
6
  /doc/
7
+ /gemfiles/*.lock
7
8
  /pkg/
8
9
  /spec/reports/
9
10
  /tmp/
10
- *.gem
@@ -1,5 +1,5 @@
1
- sudo: false
2
1
  language: ruby
2
+
3
3
  rvm:
4
- - 2.2.4
5
- before_install: gem install bundler -v 1.12.3
4
+ - 2.6
5
+ - 2.7
@@ -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`. (Native in Ruby 2.4.)
17
- * [BREAKING] Remove `String#lchomp`. (Native in Ruby 2.5 as
18
- `String#delete_prefix`.)
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
@@ -1,4 +1,8 @@
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", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
8
+ gem "benchmark-inputs", "~> 1.0"
data/README.md CHANGED
@@ -1,72 +1,45 @@
1
- # casual_support
2
-
3
- Utility methods as extensions to Ruby core objects, a la Active Support.
4
-
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
-
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)
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 from [Ruby Gems](https://rubygems.org/gems/casual_support):
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 script:
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. You can also run `rake irb` for an
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"
@@ -1,30 +1,26 @@
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 = ">= 2.6"
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["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
@@ -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"
@@ -5,7 +5,7 @@ class Date
5
5
 
6
6
  # Alias of +Date#to_s+. Formats the Date as "YYYY-MM-DD".
7
7
  #
8
- # Provided for parity with {Time#to_hms}.
8
+ # Provided for parity with {Time#to_ymd}.
9
9
  #
10
10
  # @return [String]
11
11
  alias :to_ymd :to_s
@@ -2,16 +2,16 @@ require_relative "../hash/putbang"
2
2
 
3
3
  module Enumerable
4
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.
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 ['K]
13
- # @yieldreturn ['V]
14
- # @return [Hash<'K, 'V>]
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 a key with a value, and returns the key's previously
4
- # associated value. If the key had no previously associated value,
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 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.
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 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
@@ -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<Symbol, Object>, Hash<String, Object>]
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 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.
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<Symbol, Object>, Hash<String, Object>]
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
@@ -1,3 +1,3 @@
1
1
  module CasualSupport
2
- VERSION = "3.0.2"
2
+ VERSION = "4.0.0"
3
3
  end
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: 3.0.2
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: 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'
11
+ date: 2020-02-02 00:00:00.000000000 Z
12
+ dependencies: []
97
13
  description:
98
14
  email:
99
- - jonathan.hefner@gmail.com
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: '0'
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.0.1
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,2 +0,0 @@
1
- require_relative "comparable/at_least"
2
- require_relative "comparable/at_most"
@@ -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,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,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