ruby-refract 0.0.1

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 (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/lib/refract.rb +20 -0
  4. data/ruby-refract.gemspec +15 -0
  5. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 82520253b2d890260daf8d62cd39d737c4717e4d
4
+ data.tar.gz: 645f8dee6f52f0d7a6c23f71f62897ecf1e2551a
5
+ SHA512:
6
+ metadata.gz: 24291fea06904dba0a7a31e32664276fc3fa530d9af0f5858bcc85c6871702391a46d1abd0fb4f3e6dcee21e56d358df2fa7f9fb3e126c1c3081a573a55c4c2d
7
+ data.tar.gz: 0e8c1a17f88e9178f6fbd0d8206c4f11224b8caade69b30e4b07b29a0ee878afdc1f542c3b8ef6bd05f48bd90970c52a1d3fc0edbc063aba58f7f88b2aba8484
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Yulia Oletskaya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/lib/refract.rb ADDED
@@ -0,0 +1,20 @@
1
+ class Refract
2
+ def self.search(json, query)
3
+ fail(ArgumentError, 'Expected hash as the first argument') unless json.is_a?(Hash)
4
+ fail(ArgumentError, 'Expected hash as the second argument') unless query.is_a?(Hash)
5
+
6
+ return [] unless json['content']
7
+ return [] unless json['content'].is_a?(Array)
8
+
9
+ result = json['content'].select do |element|
10
+ query.map do |k, v|
11
+ # TODO: deep search
12
+ element[k] == v
13
+ end.all?
14
+ end
15
+
16
+ json['content'].map do |element|
17
+ search(element, query)
18
+ end.flatten.concat(result)
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ruby-refract'
3
+ s.version = '0.0.1'
4
+ s.date = '2016-01-23'
5
+ s.summary = 'Ruby Refract'
6
+ s.description = 'Ruby implementation for refract lookup'
7
+ s.authors = ['Yulia Oletskaya']
8
+ s.email = 'yulia.oletskaya@gmail.com'
9
+
10
+ s.files = `git ls-files`.split($/)
11
+ s.require_paths = ['lib']
12
+
13
+ s.homepage = 'http://rubygems.org/gems/ruby-refract'
14
+ s.license = 'MIT'
15
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-refract
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yulia Oletskaya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby implementation for refract lookup
14
+ email: yulia.oletskaya@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - lib/refract.rb
21
+ - ruby-refract.gemspec
22
+ homepage: http://rubygems.org/gems/ruby-refract
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.2.2
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Ruby Refract
46
+ test_files: []