revector 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f00522f0cf5e6aabfadf23fe8a8892497a3e7c0c9abb2ee64b0b4b2f7b3b690f
4
- data.tar.gz: 7bf974dc51348cacb8ae6bd9d148478185b7f5cb8df306cca645686d4468f49f
3
+ metadata.gz: 3346074e6247568f17b908f5472d120d2608c514c186bf2665053c867499439f
4
+ data.tar.gz: 6abde163bf710682bf19e88871b299cf8795f1aa31540e051f35da0d7ba302a3
5
5
  SHA512:
6
- metadata.gz: eaee10f684d1a0bd9c66dae55c63a62c33489fe64e1a0293f1e95e99822d99821a4c71d0693d6f10eccb0045182b8f0e642e0298a51a1865b8bcf042367d7979
7
- data.tar.gz: 3f633dc545f1a97ca2db9ded7c93fef8da5e086aebaae7fc2ad5df72043bd1be85a469f631274d34b21a217b86bc57bb08958009b61b6d89b48ea7bb66c57bdd
6
+ metadata.gz: a7e44af11b5f08a366a5c5db1444b483f95c1b8f29a547593fac2cb24c7edc7460957380fc445e20e824f8ec93b37d5d67dd603faf10b4983353b883158bed05
7
+ data.tar.gz: 36c9ba17ae6a8bb54f0673dc2d54fa40a61db5a9656cc13df38fdf64e956734c513240a6972467e7f9c1ffdf5425c808fb9545d0dbb2f623a8e919c89ca34350
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## Changelog
2
2
 
3
+ ### [v0.1.1](https://github.com/thadeu/revector/compare/v0.1.0...v0.1.1) - 11 December 2024
4
+
5
+ #### General Changes
6
+
7
+ - added support to ex and not_ex @thadeu
8
+ - update CHANGELOG.md @thadeu
9
+ - update README.md @thadeu
10
+
3
11
  ### v0.1.0
4
12
 
5
13
  #### Chores And Housekeeping
data/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
  </p>
5
5
 
6
6
  <p align="center">
7
- <a href="https://rubygems.org/gems/revector">
7
+ <a href="https://rubygems.org/gems/revector" style="text-decoration: none !important;">
8
8
  <img alt="Gem" src="https://img.shields.io/gem/v/revector.svg">
9
9
  </a>
10
10
 
11
- <a href="https://github.com/thadeu/revector/actions/workflows/ci.yml">
11
+ <a href="https://github.com/thadeu/revector/actions/workflows/ci.yml" style="text-decoration: none !important;">
12
12
  <img alt="Build Status" src="https://github.com/thadeu/revector/actions/workflows/ci.yml/badge.svg">
13
13
  </a>
14
14
  </p>
@@ -35,7 +35,7 @@ unreleased | https://github.com/thadeu/revector/blob/main/README.md
35
35
 
36
36
  | kind | branch | ruby |
37
37
  | -------------- | ------- | ------------------ |
38
- | unreleased | main | >= 2.5.8, <= 3.1.x |
38
+ | unreleased | main | >= 2.7 |
39
39
 
40
40
  ## Installation
41
41
 
@@ -67,14 +67,16 @@ Without configuration, because we use only Ruby. ❤️
67
67
  | ----------- | ----------- | ----------- |
68
68
  | Equal | eq | Anywhere |
69
69
  | NotEqual | noteq | Anywhere |
70
+ | Exists | ex | Anywhere |
71
+ | NotExists | not_ex | Anywhere |
70
72
  | Contains | cont | Anywhere |
71
- | NotContains | notcont | Anywhere |
73
+ | NotContains | notcont, not_cont | Anywhere |
72
74
  | Included | in | Anywhere |
73
- | NotIncluded | notin | Anywhere |
74
- | Start | start | Anywhere |
75
- | NotStart | notstart | Anywhere |
75
+ | NotIncluded | notin, not_in | Anywhere |
76
+ | Start | start, st | Anywhere |
77
+ | NotStart | notstart, notst, not_start, not_st | Anywhere |
76
78
  | End | end | Anywhere |
77
- | NotEnd | notend | Anywhere |
79
+ | NotEnd | notend, not_end | Anywhere |
78
80
  | LessThan | lt | Anywhere |
79
81
  | LessThanEqual | lteq | Anywhere |
80
82
  | GreaterThan | gt | Anywhere |
@@ -17,7 +17,7 @@ class Revector
17
17
  end
18
18
 
19
19
  def self.compare(value, expected_value)
20
- !Equal.compare(value, expected_value)
20
+ !Exists.compare(value) && !Equal.compare(value, expected_value)
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Revector
4
+ module Exists
5
+ def self.check!(item, iteratee)
6
+ compare(Utility::TryFetchOrBlank[item, iteratee])
7
+ end
8
+
9
+ def self.compare(value, other = false)
10
+ case value
11
+ in [*] | String
12
+ value.size.positive?.to_s == other.to_s
13
+ else
14
+ !!value.to_s == other.to_s
15
+ end
16
+ end
17
+ end
18
+
19
+ module NotExists
20
+ def self.check!(item, iteratee)
21
+ !Exists.check!(item, iteratee)
22
+ end
23
+
24
+ def self.compare(value, other = nil)
25
+ !Exists.compare(value, other)
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Revector
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
data/lib/revector.rb CHANGED
@@ -3,9 +3,10 @@
3
3
  require 'set'
4
4
 
5
5
  require_relative 'revector/utility'
6
+ require_relative 'revector/predicate/equal'
7
+ require_relative 'revector/predicate/exists'
6
8
  require_relative 'revector/predicate/startify'
7
9
  require_relative 'revector/predicate/endify'
8
- require_relative 'revector/predicate/equal'
9
10
  require_relative 'revector/predicate/contains'
10
11
  require_relative 'revector/predicate/in'
11
12
  require_relative 'revector/predicate/less_than'
@@ -54,6 +55,7 @@ class Revector
54
55
 
55
56
  case right
56
57
  in [*]
58
+ right = [''] unless right.any?
57
59
  Array(right).any? { |o| predicatable.compare(o, valueable) }
58
60
  else
59
61
  predicatable.compare(right, valueable)
@@ -67,7 +69,7 @@ class Revector
67
69
  predicate = Array(parts[-2..]).filter do |pkey|
68
70
  next unless PREDICATES.include? pkey
69
71
 
70
- parts = parts - [pkey]
72
+ parts -= [pkey]
71
73
 
72
74
  pkey
73
75
  end&.last || :eq
@@ -103,21 +105,25 @@ class Revector
103
105
  not_end: NotEndify,
104
106
  in: Included,
105
107
  notin: NotIncluded,
106
- not_in: NotIncluded
108
+ not_in: NotIncluded,
109
+ ex: Exists,
110
+ not_ex: NotExists
107
111
  }[named.to_sym || :eq]
108
112
  end
109
113
  private_constant :Predicate
110
114
 
111
115
  AFFIRMATIVES = %w[
112
- eq
116
+ eq ex
113
117
  in cont
114
118
  lt lteq
115
119
  gt gteq
116
- st start end
120
+ st start
121
+ end
117
122
  ].freeze
118
123
 
119
124
  NEGATIVES = %w[
120
125
  noteq not_eq
126
+ not_ex
121
127
  notcont not_cont
122
128
  notstart notst not_start not_st
123
129
  notend not_end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thadeu Esteves
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-11 00:00:00.000000000 Z
11
+ date: 2024-12-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Filter collections using predicates like Ransack gem.
14
14
  email:
@@ -35,6 +35,7 @@ files:
35
35
  - lib/revector/predicate/contains.rb
36
36
  - lib/revector/predicate/endify.rb
37
37
  - lib/revector/predicate/equal.rb
38
+ - lib/revector/predicate/exists.rb
38
39
  - lib/revector/predicate/greater_than.rb
39
40
  - lib/revector/predicate/in.rb
40
41
  - lib/revector/predicate/less_than.rb