philter 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +7 -0
- data/lib/array.rb +24 -10
- data/lib/base.rb +13 -0
- data/lib/philter.rb +1 -0
- data/lib/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a82097224d3bcea151e212c83dcd4736f0ed43bd
|
4
|
+
data.tar.gz: 54f2e0976d20d9367f954ea333c2649b83517426
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5321992c7fe69306f65960b8cac88f4506e1eba6cc1a91a82653305c8e4d3172f6c3b81b465f0a5516e3e4087c2050fc13f414e0501bbfe6e1a2bbd362bfa3c5
|
7
|
+
data.tar.gz: 1935bc23a2fbdb11b77b18f4d31a97b935304b48238d54e73e5df161970f3c6f982037a174ae36edca67ad40cffc09fdcf186d0ce8dfb6550af3c04507003ace
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
v0.3.0 [☰](https://github.com/marcomd/Philter/compare/v0.2.0...v0.3.0) May 19th, 2016
|
2
|
+
------------------------------
|
3
|
+
* Added operators to work with fixnum: id: '<3' or any other operator
|
4
|
+
* Improved documentation
|
5
|
+
|
1
6
|
v0.2.0 [☰](https://github.com/marcomd/Philter/compare/v0.1.0...v0.2.0) May 19th, 2016
|
2
7
|
------------------------------
|
3
8
|
* Added options `:get` to select attributes from hashes and objects
|
data/README.md
CHANGED
@@ -41,6 +41,13 @@ require 'philter'
|
|
41
41
|
].philter id: [1,3]
|
42
42
|
=> [{:id=>1, :name=>"Mark"}, {:id=>3, :name=>"Bill"}]
|
43
43
|
|
44
|
+
[
|
45
|
+
{id: 1, name: 'Mark' },
|
46
|
+
{id: 2, name: 'Larry' },
|
47
|
+
{id: 3, name: 'Bill' }
|
48
|
+
].philter id: '>2'
|
49
|
+
=> [{:id=>3, :name=>"Bill"}]
|
50
|
+
|
44
51
|
# Regular expression
|
45
52
|
[
|
46
53
|
{id: 1, name: 'Mark', email: 'mark@gmail.com' },
|
data/lib/array.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Array
|
2
|
+
include Philter::Base
|
2
3
|
def philter search=nil, options={}
|
3
4
|
options = {
|
4
5
|
get: nil,
|
@@ -24,7 +25,7 @@ class Array
|
|
24
25
|
puts help if options[:debug]
|
25
26
|
raise "Specify search parameter!"
|
26
27
|
end
|
27
|
-
|
28
|
+
default_operator = '=='
|
28
29
|
results = []
|
29
30
|
self.each do |item|
|
30
31
|
puts "item #{item.class.name} #{item}" if options[:debug]
|
@@ -47,9 +48,14 @@ class Array
|
|
47
48
|
print "| #{item.send(label)} =~ #{value}" if options[:debug]
|
48
49
|
selected = item.send(label) =~ value
|
49
50
|
else
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
# search: {id: 2}
|
52
|
+
# search: {id: '<3'} or any other operator
|
53
|
+
operator = get_operator value
|
54
|
+
tmp_value = operator ? value.gsub(operator,'').to_i : value
|
55
|
+
operator ||= default_operator
|
56
|
+
print " .2 #{item.class.name}.#{label} #{operator} value " if options[:debug]
|
57
|
+
print "| #{item.send(label)} #{operator} #{tmp_value}" if options[:debug]
|
58
|
+
selected = eval("item.send(label) #{operator} tmp_value")
|
53
59
|
end
|
54
60
|
elsif item.respond_to? '[]'
|
55
61
|
print " 1.y label: #{label.class.name}" if options[:debug]
|
@@ -60,9 +66,13 @@ class Array
|
|
60
66
|
selected = value === item[label].to_s
|
61
67
|
elsif item.is_a?(Hash) && !label.is_a?(Fixnum)
|
62
68
|
# search: {id: 1} or {'name' => 'Mark'}
|
63
|
-
|
64
|
-
|
65
|
-
|
69
|
+
# search: {id: '<3'} or any other operator
|
70
|
+
operator = get_operator value
|
71
|
+
tmp_value = operator ? value.gsub(operator,'').to_i : value
|
72
|
+
operator ||= default_operator
|
73
|
+
print " .2 #{item.class.name}[:#{label}] #{operator} value " if options[:debug]
|
74
|
+
print "| #{item[label]} #{operator} #{tmp_value}" if options[:debug]
|
75
|
+
selected = eval("item[label] #{operator} tmp_value")
|
66
76
|
else
|
67
77
|
print " .3 no action for #{value} !!!" if options[:debug]
|
68
78
|
end
|
@@ -99,9 +109,13 @@ class Array
|
|
99
109
|
else
|
100
110
|
# Search has one item
|
101
111
|
# search: 3 or search: 'a'
|
102
|
-
|
103
|
-
|
104
|
-
|
112
|
+
# search: '<3' or any other operator
|
113
|
+
operator = get_operator search
|
114
|
+
tmp_search = operator ? search.gsub(operator,'').to_i : search
|
115
|
+
operator ||= default_operator
|
116
|
+
print " c. item #{operator} search " if options[:debug]
|
117
|
+
print "| #{item} #{operator} #{tmp_search}" if options[:debug]
|
118
|
+
selected = eval("item #{operator} tmp_search")
|
105
119
|
puts " #{'=> X' if selected}" if options[:debug]
|
106
120
|
condition[:at_least_one] ||= selected
|
107
121
|
end
|
data/lib/base.rb
ADDED
data/lib/philter.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Mastrodonato
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- LICENSE
|
37
37
|
- README.md
|
38
38
|
- lib/array.rb
|
39
|
+
- lib/base.rb
|
39
40
|
- lib/philter.rb
|
40
41
|
- lib/version.rb
|
41
42
|
homepage: https://github.com/marcomd/philter
|