put 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 833121595321bacc22e213e447580f40bbbe1500670d5072c582ae54624b468f
4
- data.tar.gz: 07dd91f2ae928542e6d4ed42d046ed628fd6a28ef13978cba7ab811796128d92
3
+ metadata.gz: 946be21b2839e39c50fccfc55683ec69b8aa1d888a4030cd93aa3ff59f17ff18
4
+ data.tar.gz: 9cd544f2130f11a1285eaeeaff6b695ac3ca80513b721783836a4d7526b70178
5
5
  SHA512:
6
- metadata.gz: 37a54ae5099e675f9819d4f53e754b481d9ed7b8ad10623ca1978a0277f94e61b6acbc4eac6b0949f1a8dd9ea1e780571f4a6e5b655f493f6ecf11f1687c26f9
7
- data.tar.gz: 568dcf85f64510b6b8d8fedc70adc1740339893413a2dfad8a9f42d4f512a2dbbdf2b344356d0fcd38b4b320dbd09bb939a471e1d384b92078d4a74f37a3d631
6
+ metadata.gz: 057e1c3b3b7bcb4b8b79e9a98ec132f1c9d6faa03defb3095ae0d2fa5eaeed7b74e3d39d8bda3ab280d8b594e492b493008d1711349d1a11ddea6c1e95802eee
7
+ data.tar.gz: 2d093be68e236968499608dbd183ffbd99e7664cb6d3a929e0f15bbc904a0f86905a187f2f0046902bab0b055c5dd29399d1cf53a684e36f12a2e19e4bbcdf4b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [0.1.0] - 2022-09-21
3
+ ## [0.0.2] - 2022-09-21
4
+
5
+ - Add support for Put.asc, Put.desc, and whether nils go first or last
6
+
7
+ ## [0.0.1] - 2022-09-21
4
8
 
5
9
  - Initial release
data/Gemfile CHANGED
@@ -1,12 +1,8 @@
1
- # frozen_string_literal: true
2
-
3
1
  source "https://rubygems.org"
4
2
 
5
- # Specify your gem's dependencies in put.gemspec
6
3
  gemspec
7
4
 
8
- gem "rake", "~> 13.0"
9
-
10
- gem "minitest", "~> 5.0"
11
-
12
- gem "standard", "~> 1.3"
5
+ gem "debug"
6
+ gem "rake"
7
+ gem "minitest"
8
+ gem "standard"
data/Gemfile.lock CHANGED
@@ -1,12 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- put (0.0.1)
4
+ put (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ast (2.4.2)
10
+ debug (1.6.2)
11
+ irb (>= 1.3.6)
12
+ reline (>= 0.3.1)
13
+ io-console (0.5.11)
14
+ irb (1.4.1)
15
+ reline (>= 0.3.0)
10
16
  json (2.6.2)
11
17
  minitest (5.16.3)
12
18
  parallel (1.22.1)
@@ -15,6 +21,8 @@ GEM
15
21
  rainbow (3.1.1)
16
22
  rake (13.0.6)
17
23
  regexp_parser (2.5.0)
24
+ reline (0.3.1)
25
+ io-console (~> 0.5)
18
26
  rexml (3.2.5)
19
27
  rubocop (1.35.1)
20
28
  json (~> 2.3)
@@ -39,12 +47,14 @@ GEM
39
47
 
40
48
  PLATFORMS
41
49
  arm64-darwin-21
50
+ arm64-darwin-22
42
51
 
43
52
  DEPENDENCIES
44
- minitest (~> 5.0)
53
+ debug
54
+ minitest
45
55
  put!
46
- rake (~> 13.0)
47
- standard (~> 1.3)
56
+ rake
57
+ standard
48
58
 
49
59
  BUNDLED WITH
50
60
  2.3.22
data/README.md CHANGED
@@ -1,33 +1,17 @@
1
1
  # Put
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/put`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Put helps you put stuff in order when using
4
+ [Enumerable#sort_by](https://ruby-doc.org/core-3.1.2/Enumerable.html#method-i-sort_by).
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
6
+ A neat trick when implementing complex sorting rules is to map them to an
7
+ array of arrays of comparable elements in priority-order.
6
8
 
7
- ## Installation
8
9
 
9
- Install the gem and add to the application's Gemfile by executing:
10
+ ## Code of Conduct
10
11
 
11
- $ bundle add put
12
-
13
- If bundler is not being used to manage dependencies, install the gem by executing:
14
-
15
- $ gem install put
16
-
17
- ## Usage
18
-
19
- TODO: Write usage instructions here
20
-
21
- ## Development
22
-
23
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
-
25
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
-
27
- ## Contributing
28
-
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/searls/put.
30
-
31
- ## License
32
-
33
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
12
+ This project follows Test Double's [code of
13
+ conduct](https://testdouble.com/code-of-conduct) for all community interactions,
14
+ including (but not limited to) one-on-one communications, public posts/comments,
15
+ code reviews, pull requests, and GitHub issues. If violations occur, Test Double
16
+ will take any action they deem appropriate for the infraction, up to and
17
+ including blocking a user from the organization's repositories.
data/Rakefile CHANGED
@@ -1,12 +1,10 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "bundler/gem_tasks"
4
2
  require "rake/testtask"
5
3
 
6
4
  Rake::TestTask.new(:test) do |t|
7
5
  t.libs << "test"
8
6
  t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
7
+ t.test_files = FileList["test/**/*_test.rb"]
10
8
  end
11
9
 
12
10
  require "standard/rake"
@@ -0,0 +1,12 @@
1
+ module Put
2
+ module NilExtension
3
+ def <=>(other)
4
+ if ::Put::PutsThing === other
5
+ -(other <=> self)
6
+ else
7
+ super
8
+ end
9
+ end
10
+ end
11
+ ::NilClass.prepend(NilExtension)
12
+ end
@@ -0,0 +1,65 @@
1
+ module Put
2
+ class PutsThing
3
+ def <=>(other)
4
+ if value.nil? && (other.nil? || other&.value.nil?)
5
+ 0
6
+ elsif value.nil?
7
+ nils_first? ? -1 : 1
8
+ elsif other.nil? || other&.value.nil?
9
+ nils_first? ? 1 : -1
10
+ elsif other && !other.reverse?
11
+ value <=> other.value
12
+ elsif other&.reverse?
13
+ other.value <=> value
14
+ else
15
+ value <=> 0
16
+ end
17
+ end
18
+
19
+ def reverse?
20
+ false
21
+ end
22
+
23
+ def nils_first?
24
+ false
25
+ end
26
+
27
+ class First < PutsThing
28
+ def value
29
+ -Float::INFINITY
30
+ end
31
+ end
32
+
33
+ class Last < PutsThing
34
+ def value
35
+ Float::INFINITY
36
+ end
37
+
38
+ def nils_first?
39
+ true
40
+ end
41
+ end
42
+
43
+ class InOrder < PutsThing
44
+ def initialize(value, nils_first:)
45
+ @value = value
46
+ @nils_first = nils_first
47
+ end
48
+
49
+ attr_reader :value
50
+
51
+ def nils_first?
52
+ @nils_first
53
+ end
54
+ end
55
+
56
+ class Ascending < InOrder
57
+ end
58
+
59
+ class Descending < InOrder
60
+ def reverse?
61
+ true
62
+ end
63
+ end
64
+ end
65
+ end
data/lib/put/version.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- class Put
4
- VERSION = "0.0.1"
1
+ module Put
2
+ VERSION = "0.0.2"
5
3
  end
data/lib/put.rb CHANGED
@@ -1,38 +1,21 @@
1
1
  require_relative "put/version"
2
+ require_relative "put/nil_ext"
3
+ require_relative "put/puts_thing"
2
4
 
3
- class Put
5
+ module Put
4
6
  def self.first
5
- First
7
+ @@first ||= PutsThing::First.new.freeze
6
8
  end
7
9
 
8
10
  def self.last
9
- Last
11
+ @@last ||= PutsThing::Last.new.freeze
10
12
  end
11
13
 
12
- def initialize(value)
13
- @value = value
14
+ def self.desc(value, nils_first: false)
15
+ PutsThing::Descending.new(value, nils_first: nils_first)
14
16
  end
15
17
 
16
- First = new(-1).freeze
17
- Last = new(1).freeze
18
-
19
- def <=>(other)
20
- @value <=> if other
21
- other.value
22
- else
23
- 0
24
- end
25
- end
26
-
27
- module NilExtension
28
- def <=>(other)
29
- if ::Put === other
30
- -(other <=> self)
31
- else
32
- super
33
- end
34
- end
18
+ def self.asc(value, nils_first: false)
19
+ PutsThing::Ascending.new(value, nils_first: nils_first)
35
20
  end
36
-
37
- ::NilClass.prepend(NilExtension)
38
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: put
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -25,6 +25,8 @@ files:
25
25
  - README.md
26
26
  - Rakefile
27
27
  - lib/put.rb
28
+ - lib/put/nil_ext.rb
29
+ - lib/put/puts_thing.rb
28
30
  - lib/put/version.rb
29
31
  - put.gemspec
30
32
  - sig/put.rbs
@@ -50,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
52
  - !ruby/object:Gem::Version
51
53
  version: '0'
52
54
  requirements: []
53
- rubygems_version: 3.3.20
55
+ rubygems_version: 3.3.7
54
56
  signing_key:
55
57
  specification_version: 4
56
58
  summary: Put helps you write prioritized, multi-variate sort_by blocks