searchy-json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fe529669801a003456d7f54dcfcd57d47653bf606276a04af5cb1c39ec9c481f
4
+ data.tar.gz: c0007866b0c080c0c9ee83d1e19e0b94dec87235ef706808e6900d5312a0d9a6
5
+ SHA512:
6
+ metadata.gz: 6966ed11b0b10a76ee192e28246e4e87e2464aca5a6d87586016ec60172c095f1a61d7bf462df522802304447eba265e62655b1ce218edd191b1f08c72162f29
7
+ data.tar.gz: e3b7cb2acaa84f6433d576519492eb3114d7a1f232c10a785292fa84b4838f128266357664e803abeec2c68d0ed99a27be1014f8e9df7ecddc369f3d7365eeb1
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ /vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format documentation
3
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ StyleGuideCopsOnly: true
5
+ TargetRubyVersion: 2.4.1
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ Documentation:
11
+ Enabled: false
12
+
13
+ FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Metrics/ModuleLength:
17
+ Exclude:
18
+ - spec/**/*_spec.rb
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at yaroslav.bezrukavyi@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in searchy.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ searchy (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.2)
13
+ parser (2.6.2.0)
14
+ ast (~> 2.4.0)
15
+ powerpack (0.1.2)
16
+ pry (0.12.2)
17
+ coderay (~> 1.1.0)
18
+ method_source (~> 0.9.0)
19
+ rainbow (2.2.2)
20
+ rake
21
+ rake (10.5.0)
22
+ rspec (3.8.0)
23
+ rspec-core (~> 3.8.0)
24
+ rspec-expectations (~> 3.8.0)
25
+ rspec-mocks (~> 3.8.0)
26
+ rspec-core (3.8.0)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-expectations (3.8.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-mocks (3.8.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-support (3.8.0)
35
+ rubocop (0.48.1)
36
+ parser (>= 2.3.3.1, < 3.0)
37
+ powerpack (~> 0.1)
38
+ rainbow (>= 1.99.1, < 3.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (~> 1.0, >= 1.0.1)
41
+ ruby-progressbar (1.10.0)
42
+ unicode-display_width (1.5.0)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.17)
49
+ pry (~> 0.12)
50
+ rake (~> 10.0)
51
+ rspec (~> 3.0)
52
+ rubocop (~> 0.48.0)
53
+ searchy!
54
+
55
+ BUNDLED WITH
56
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 bezrukavyi
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Searchy
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/searchy`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'searchy'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install searchy
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/searchy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Searchy project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/searchy/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "searchy"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/searchy.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'json'
2
+ require 'searchy/version'
3
+ require 'searchy/data'
4
+ require 'searchy/query'
5
+ require 'searchy/extracter'
6
+ require 'searchy/service'
7
+
8
+ module Searchy
9
+ class Error < StandardError; end
10
+ end
@@ -0,0 +1,43 @@
1
+ module Searchy
2
+ class Data
3
+ attr_reader :data_path, :primary_key, :search_fields, :scope
4
+
5
+ def initialize(data_path, primary_key:, search_fields: [])
6
+ @data_path = data_path
7
+ @primary_key = primary_key
8
+ @search_fields = search_fields
9
+ end
10
+
11
+ def call
12
+ @scope = parsed_data
13
+ @scope = collected_by_primary_key
14
+ @scope = sort_by_relevant
15
+
16
+ scope
17
+ end
18
+
19
+ private
20
+
21
+ def collected_by_primary_key
22
+ scope.inject({}) do |new_scope, data_item|
23
+ key = data_item[primary_key]
24
+ values = formatted_data(data_item)
25
+
26
+ new_scope.merge(key => values)
27
+ end
28
+ end
29
+
30
+ def sort_by_relevant
31
+ scope.sort_by { |_primary_field, characters| characters.size }.to_h
32
+ end
33
+
34
+ def parsed_data
35
+ @parsed_data ||= JSON.parse(File.read(data_path))
36
+ end
37
+
38
+ def formatted_data(data_item)
39
+ values = data_item.slice(*search_fields).values.flatten
40
+ values.map { |item| item.delete(',').upcase.split(' ') }.flatten.uniq
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,60 @@
1
+ module Searchy
2
+ class Extracter
3
+ attr_reader :data, :query, :negative_keywords, :positive_keywords, :exact_matches
4
+
5
+ def initialize(data, query)
6
+ @data = data
7
+ @query = query
8
+ @negative_keywords = query.negative_keywords
9
+ @positive_keywords = query.positive_keywords
10
+ end
11
+
12
+ def call
13
+ query.exact_matches? ? exact_extract : match_extract
14
+ end
15
+
16
+ private
17
+
18
+ def match_extract
19
+ result = {}
20
+
21
+ data.each do |primary_field, keywords|
22
+ negative_diff_size = keywords_diff_size(keywords, :negative)
23
+ next if contain_negative?(negative_diff_size)
24
+
25
+ positive_diff_size = keywords_diff_size(keywords, :positive)
26
+ next unless contain_positive?(positive_diff_size)
27
+
28
+ result[primary_field] = positive_diff_size
29
+ end
30
+
31
+ result.sort_by { |_key, index| index }.map(&:first)
32
+ end
33
+
34
+ def exact_extract
35
+ result = []
36
+
37
+ data.each do |primary_field, keywords|
38
+ result << primary_field if full_positive_match?(keywords)
39
+ end
40
+
41
+ result
42
+ end
43
+
44
+ def contain_negative?(negative_diff)
45
+ negative_diff != negative_keywords.count
46
+ end
47
+
48
+ def contain_positive?(positive_diff)
49
+ positive_diff != positive_keywords.count
50
+ end
51
+
52
+ def full_positive_match?(keywords)
53
+ (keywords & positive_keywords).count == positive_keywords.count
54
+ end
55
+
56
+ def keywords_diff_size(keywords, type)
57
+ (send("#{type}_keywords") - keywords).count
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,50 @@
1
+ module Searchy
2
+ class Query
3
+ attr_reader :text
4
+
5
+ NEGATIVE = /\A-/.freeze
6
+ START_EXTRACT = /\A("|')/.freeze
7
+ END_EXTRACT = /("|')\Z/.freeze
8
+
9
+ def initialize(text)
10
+ @text = text
11
+ end
12
+
13
+ def negative_keywords
14
+ keywords_by_type[:negative]
15
+ end
16
+
17
+ def positive_keywords
18
+ keywords_by_type[:positive]
19
+ end
20
+
21
+ def exact_matches?
22
+ @exact_matches ||= !(text =~ START_EXTRACT && text =~ END_EXTRACT).nil?
23
+ end
24
+
25
+ private
26
+
27
+ def keywords_by_type
28
+ @keywords_by_type ||= exact_keywords_by_type
29
+ end
30
+
31
+ def exact_keywords_by_type
32
+ negative = []
33
+ positive = []
34
+
35
+ keywords.each do |word|
36
+ negative?(word) ? negative.push(word.gsub(NEGATIVE, '')) : positive.push(word)
37
+ end
38
+
39
+ { negative: negative, positive: positive }
40
+ end
41
+
42
+ def negative?(keyword)
43
+ keyword =~ NEGATIVE
44
+ end
45
+
46
+ def keywords
47
+ @keywords ||= text.gsub(START_EXTRACT, '').gsub(END_EXTRACT, '').upcase.split(' ')
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ module Searchy
2
+ class Service
3
+ attr_reader :data_path, :primary_key, :search_fields
4
+
5
+ def initialize(data_path:, primary_key:, search_fields: [])
6
+ @data_path = data_path
7
+ @primary_key = primary_key
8
+ @search_fields = search_fields
9
+ end
10
+
11
+ def find(query)
12
+ search_query = Searchy::Query.new(query)
13
+ Extracter.new(search_data, search_query).call
14
+ end
15
+
16
+ private
17
+
18
+ def search_data
19
+ @search_data ||= Searchy::Data.new(data_path, primary_key: primary_key, search_fields: search_fields).call
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Searchy
2
+ VERSION = "0.1.0"
3
+ end
data/searchy.gemspec ADDED
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'searchy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'searchy-json'
8
+ spec.version = Searchy::VERSION
9
+ spec.authors = ['bezrukavyi']
10
+ spec.email = ['yaroslav.bezrukavyi@gmail.com']
11
+
12
+ spec.summary = 'Searchy Json'
13
+ spec.description = 'Search in JSON file'
14
+ spec.homepage = 'https://github.com/bezrukavyi/searchy-json'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.17'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.0'
25
+ spec.add_development_dependency 'pry', '~> 0.12'
26
+ spec.add_development_dependency 'rubocop', '~> 0.48.0'
27
+ end
@@ -0,0 +1,487 @@
1
+ [
2
+ {
3
+ "Name": "A+",
4
+ "Type": "Array",
5
+ "Designed by": "Arthur Whitney"
6
+ },
7
+ {
8
+ "Name": "ActionScript",
9
+ "Type": "Compiled, Curly-bracket, Procedural, Reflective, Scripting, Object-oriented class-based",
10
+ "Designed by": "Gary Grossman"
11
+ },
12
+ {
13
+ "Name": "Ada",
14
+ "Type": "Compiled, Imperative, Procedural, Object-oriented class-based",
15
+ "Designed by": "Tucker Taft, Jean Ichbiah"
16
+ },
17
+ {
18
+ "Name": "Aldor",
19
+ "Type": "Iterative",
20
+ "Designed by": "Richard Dimick Jenks, Barry Trager, Stephen Watt, James Davenport, Robert Sutor, Scott Morrison"
21
+ },
22
+ {
23
+ "Name": "Alef",
24
+ "Type": "Curly-bracket",
25
+ "Designed by": "Phil Winterbottom"
26
+ },
27
+ {
28
+ "Name": "ALGOL",
29
+ "Type": "Compiled, Imperative, Procedural",
30
+ "Designed by": "Bauer, Bottenbruch, Rutishauser, Samelson, Backus, Katz, Perlis, Wegstein, Naur, Vauquois, van Wijngaarden, Woodger, Green, McCarthy"
31
+ },
32
+ {
33
+ "Name": "Ant",
34
+ "Type": "Interpreted",
35
+ "Designed by": "Apache Software Foundation"
36
+ },
37
+ {
38
+ "Name": "APL",
39
+ "Type": "Array, Interactive mode, Interpreted",
40
+ "Designed by": "Kenneth E. Iverson"
41
+ },
42
+ {
43
+ "Name": "AppleScript",
44
+ "Type": "Scripting",
45
+ "Designed by": "Apple Inc."
46
+ },
47
+ {
48
+ "Name": "AWK",
49
+ "Type": "Curly-bracket, Scripting",
50
+ "Designed by": "Alfred Aho, Peter Weinberger, Brian Kernighan"
51
+ },
52
+ {
53
+ "Name": "B",
54
+ "Type": "Curly-bracket",
55
+ "Designed by": "Ken Thompson"
56
+ },
57
+ {
58
+ "Name": "bash",
59
+ "Type": "Command line interface, Scripting",
60
+ "Designed by": "Brian Fox"
61
+ },
62
+ {
63
+ "Name": "BASIC",
64
+ "Type": "Imperative, Compiled, Procedural, Interactive mode, Interpreted",
65
+ "Designed by": "John George Kemeny, Thomas Eugene Kurtz"
66
+ },
67
+ {
68
+ "Name": "BCPL",
69
+ "Type": "Compiled, Curly-bracket, Procedural",
70
+ "Designed by": "Martin Richards"
71
+ },
72
+ {
73
+ "Name": "Blue",
74
+ "Type": "Imperative, Object-oriented class-based, Procedural",
75
+ "Designed by": "University of Sydney"
76
+ },
77
+ {
78
+ "Name": "C",
79
+ "Type": "Compiled, Curly-bracket, Imperative, Procedural",
80
+ "Designed by": "Dennis Ritchie"
81
+ },
82
+ {
83
+ "Name": "C#",
84
+ "Type": "Compiled, Curly-bracket, Iterative, Object-oriented class-based, Reflective, Procedural",
85
+ "Designed by": "Microsoft"
86
+ },
87
+ {
88
+ "Name": "C++",
89
+ "Type": "Compiled, Curly-bracket, Imperative, Metaprogramming, Object-oriented class-based, Procedural",
90
+ "Designed by": "Bjarne Stroustrup"
91
+ },
92
+ {
93
+ "Name": "Candle",
94
+ "Type": "Curly-bracket, Scripting",
95
+ "Designed by": "Henry Luo"
96
+ },
97
+ {
98
+ "Name": "Chapel",
99
+ "Type": "Array",
100
+ "Designed by": "David Callahan, Hans Zima, Brad Chamberlain, John Plevyak"
101
+ },
102
+ {
103
+ "Name": "ChucK",
104
+ "Type": "Curly-bracket, Object-oriented class-based, Reflective, Procedural",
105
+ "Designed by": "Ge Wang"
106
+ },
107
+ {
108
+ "Name": "Cilk",
109
+ "Type": "Curly-bracket",
110
+ "Designed by": "MIT"
111
+ },
112
+ {
113
+ "Name": "Clojure",
114
+ "Type": "Interactive mode, Reflective",
115
+ "Designed by": "Rich Hickey"
116
+ },
117
+ {
118
+ "Name": "COBOL",
119
+ "Type": "Compiled, Imperative, Procedural",
120
+ "Designed by": "Grace Hopper, William Selden, Gertrude Tierney, Howard Bromberg, Howard Discount, Vernon Reeves, Jean E. Sammet"
121
+ },
122
+ {
123
+ "Name": "Cobra",
124
+ "Type": "Compiled, Iterative, Object-oriented class-based, Procedural, Reflective",
125
+ "Designed by": "Charles Esterbrook"
126
+ },
127
+ {
128
+ "Name": "ColdFusion",
129
+ "Type": "Object-oriented class-based, Procedural, Scripting",
130
+ "Designed by": "Adobe Systems"
131
+ },
132
+ {
133
+ "Name": "Common Lisp",
134
+ "Type": "Compiled, Interactive mode, Object-oriented class-based, Reflective",
135
+ "Designed by": "Scott Fahlman, Richard P. Gabriel, Dave Moon, Guy Steele, Dan Weinreb"
136
+ },
137
+ {
138
+ "Name": "csh",
139
+ "Type": "Command line interface",
140
+ "Designed by": "Bill Joy"
141
+ },
142
+ {
143
+ "Name": "Curl",
144
+ "Type": "Compiled, Metaprogramming, Object-oriented class-based, Procedural, Reflective",
145
+ "Designed by": "Steve Ward"
146
+ },
147
+ {
148
+ "Name": "Cyclone",
149
+ "Type": "Curly-bracket",
150
+ "Designed by": "AT&T Labs"
151
+ },
152
+ {
153
+ "Name": "D",
154
+ "Type": "Compiled, Curly-bracket, Imperative, Metaprogramming, Object-oriented class-based, Procedural",
155
+ "Designed by": "Walter Bright, Andrei Alexandrescu"
156
+ },
157
+ {
158
+ "Name": "DASL",
159
+ "Type": "Object-oriented class-based, Curly-bracket, Procedural",
160
+ "Designed by": "Sun Microsystems Laboratories"
161
+ },
162
+ {
163
+ "Name": "Delphi",
164
+ "Type": "Compiled, Object-oriented class-based, Reflective",
165
+ "Designed by": "Apple, Niklaus Wirth, Anders Hejlsberg"
166
+ },
167
+ {
168
+ "Name": "E",
169
+ "Type": "Curly-bracket, Object-oriented class-based",
170
+ "Designed by": "Mark S. Miller"
171
+ },
172
+ {
173
+ "Name": "ECMAScript",
174
+ "Type": "Curly-bracket, Procedural, Reflective, Scripting",
175
+ "Designed by": "Brendan Eich, Ecma International"
176
+ },
177
+ {
178
+ "Name": "Eiffel",
179
+ "Type": "Compiled, Object-oriented class-based, Procedural, Reflective",
180
+ "Designed by": "Bertrand Meyer"
181
+ },
182
+ {
183
+ "Name": "Erlang",
184
+ "Type": "Compiled, Interactive mode",
185
+ "Designed by": "Joe Armstrong"
186
+ },
187
+ {
188
+ "Name": "Expect",
189
+ "Type": "Command line interface",
190
+ "Designed by": "Don Libes"
191
+ },
192
+ {
193
+ "Name": "F#",
194
+ "Type": "Interactive mode",
195
+ "Designed by": "Microsoft Research, Don Syme"
196
+ },
197
+ {
198
+ "Name": "Factor",
199
+ "Type": "Compiled",
200
+ "Designed by": "Slava Pestov"
201
+ },
202
+ {
203
+ "Name": "Fancy",
204
+ "Type": "Compiled, Interactive mode, Metaprogramming, Object-oriented class-based, Scripting",
205
+ "Designed by": "Christopher Bertels"
206
+ },
207
+ {
208
+ "Name": "Forth",
209
+ "Type": "Compiled, Interactive mode, Metaprogramming, Reflective",
210
+ "Designed by": "Charles H. Moore"
211
+ },
212
+ {
213
+ "Name": "Fortran",
214
+ "Type": "Array, Compiled, Imperative, Procedural",
215
+ "Designed by": "John Backus"
216
+ },
217
+ {
218
+ "Name": "Go",
219
+ "Type": "Compiled, Imperative, Procedural",
220
+ "Designed by": "Robert Griesemer, Rob Pike, Ken Thompson"
221
+ },
222
+ {
223
+ "Name": "Gosu",
224
+ "Type": "Compiled",
225
+ "Designed by": "Guidewire Software"
226
+ },
227
+ {
228
+ "Name": "Groovy",
229
+ "Type": "Compiled, Curly-bracket, Interpreted, Metaprogramming, Object-oriented class-based, Procedural, Reflective, Scripting",
230
+ "Designed by": "James Strachan"
231
+ },
232
+ {
233
+ "Name": "Hamilton C shell",
234
+ "Type": "Command line interface",
235
+ "Designed by": "Nicole Hamilton"
236
+ },
237
+ {
238
+ "Name": "Harbour",
239
+ "Type": "Compiled, Object-oriented class-based, Procedural, Reflective",
240
+ "Designed by": "Antonio Linares"
241
+ },
242
+ {
243
+ "Name": "Haskell",
244
+ "Type": "Compiled, Functional, Metaprogramming, Interpreted, Interactive mode",
245
+ "Designed by": "Simon Peyton Jones, Lennart Augustsson, Dave Barton, Brian Boutel, Warren Burton, Joseph Fasel, Kevin Hammond, Ralf Hinze, Paul Hudak, John Hughes, Thomas Johnsson, Mark Jones, John Launchbury, Erik Meijer, John Peterson, Alastair Reid, Colin Runciman, Philip Wadler"
246
+ },
247
+ {
248
+ "Name": "IDL",
249
+ "Type": "Array, Interactive mode",
250
+ "Designed by": "David Stern"
251
+ },
252
+ {
253
+ "Name": "J",
254
+ "Type": "Array, Interactive mode, Interpreted, Object-oriented class-based",
255
+ "Designed by": "Ken Iverson, Roger Hui"
256
+ },
257
+ {
258
+ "Name": "Java",
259
+ "Type": "Compiled, Curly-bracket, Imperative, Object-oriented class-based, Procedural, Reflective",
260
+ "Designed by": "James Gosling, Sun Microsystems"
261
+ },
262
+ {
263
+ "Name": "JavaScript",
264
+ "Type": "Curly-bracket, Interpreted, Reflective, Procedural, Scripting, Interactive mode",
265
+ "Designed by": "Brendan Eich"
266
+ },
267
+ {
268
+ "Name": "JOVIAL",
269
+ "Type": "Compiled, Procedural",
270
+ "Designed by": "System Development Corporation"
271
+ },
272
+ {
273
+ "Name": "JScript",
274
+ "Type": "Curly-bracket, Procedural, Reflective, Scripting",
275
+ "Designed by": "Microsoft"
276
+ },
277
+ {
278
+ "Name": "Julia",
279
+ "Type": "Array, Imperative, Interactive mode, Interpreted, Metaprogramming, Object-oriented class-based, Reflective, Scripting",
280
+ "Designed by": "Jeff Bezanson, Stefan Karpinski, Viral B. Shah, Alan Edelman"
281
+ },
282
+ {
283
+ "Name": "K",
284
+ "Type": "Array",
285
+ "Designed by": "Arthur Whitney"
286
+ },
287
+ {
288
+ "Name": "ksh",
289
+ "Type": "Command line interface",
290
+ "Designed by": "David Korn"
291
+ },
292
+ {
293
+ "Name": "Lasso",
294
+ "Type": "Procedural, Scripting, Object-oriented class-based",
295
+ "Designed by": "Kyle Jessup"
296
+ },
297
+ {
298
+ "Name": "Limbo",
299
+ "Type": "Curly-bracket",
300
+ "Designed by": "Sean Dorward, Phil Winterbottom, Rob Pike"
301
+ },
302
+ {
303
+ "Name": "Lisp",
304
+ "Type": "Metaprogramming, Reflective",
305
+ "Designed by": "John McCarthy"
306
+ },
307
+ {
308
+ "Name": "Lua",
309
+ "Type": "Imperative, Interactive mode, Interpreted, Iterative, Metaprogramming, Object-oriented class-based, Reflective, Scripting",
310
+ "Designed by": "Roberto Ierusalimschy, Waldemar Celes, Luiz Henrique de Figueiredo"
311
+ },
312
+ {
313
+ "Name": "MATLAB",
314
+ "Type": "Array, Imperative, Interactive mode, Procedural",
315
+ "Designed by": "MathWorks"
316
+ },
317
+ {
318
+ "Name": "Mercury",
319
+ "Type": "Compiled, Functional",
320
+ "Designed by": "Zoltan Somogyi"
321
+ },
322
+ {
323
+ "Name": "ML",
324
+ "Type": "Compiled, Interactive mode",
325
+ "Designed by": "Robin Milner"
326
+ },
327
+ {
328
+ "Name": "Nemerle",
329
+ "Type": "Compiled, Curly-bracket, Metaprogramming, Object-oriented class-based, Procedural",
330
+ "Designed by": "Kamil Skalski, Michal Moskal, Prof. Leszek Pacholski, Pawel Olszta"
331
+ },
332
+ {
333
+ "Name": "Obix",
334
+ "Type": "Compiled, Interactive mode, Object-oriented class-based, Procedural, Reflective, Scripting",
335
+ "Designed by": "Christian Neumanns"
336
+ },
337
+ {
338
+ "Name": "Objective-C",
339
+ "Type": "Compiled, Reflective, Object-oriented class-based",
340
+ "Designed by": "Brad Cox, Tom Love"
341
+ },
342
+ {
343
+ "Name": "Pascal",
344
+ "Type": "Compiled, Imperative, Interpreted",
345
+ "Designed by": "Niklaus Wirth"
346
+ },
347
+ {
348
+ "Name": "Perl",
349
+ "Type": "Curly-bracket, Imperative, Interactive mode, Interpreted, Metaprogramming, Procedural, Reflective, Scripting, Object-oriented class-based",
350
+ "Designed by": "Larry Wall"
351
+ },
352
+ {
353
+ "Name": "PHP",
354
+ "Type": "Curly-bracket, Imperative, Interpreted, Object-oriented class-based, Reflective, Scripting",
355
+ "Designed by": "Rasmus Lerdorf"
356
+ },
357
+ {
358
+ "Name": "Python",
359
+ "Type": "Imperative, Interactive mode, Interpreted, Iterative, Metaprogramming, Procedural, Reflective, Scripting, Object-oriented class-based",
360
+ "Designed by": "Guido van Rossum"
361
+ },
362
+ {
363
+ "Name": "R",
364
+ "Type": "Curly-bracket, Interactive mode, Interpreted, Procedural, Scripting",
365
+ "Designed by": "Ross Ihaka, Robert Gentleman"
366
+ },
367
+ {
368
+ "Name": "REXX",
369
+ "Type": "Command line interface, Interactive mode, Interpreted, Scripting",
370
+ "Designed by": "Mike Cowlishaw"
371
+ },
372
+ {
373
+ "Name": "RPG",
374
+ "Type": "Compiled, Procedural",
375
+ "Designed by": "IBM"
376
+ },
377
+ {
378
+ "Name": "Ruby",
379
+ "Type": "Imperative, Interpreted, Metaprogramming, Object-oriented class-based, Reflective, Scripting, Interactive mode",
380
+ "Designed by": "Yukihiro Matsumoto"
381
+ },
382
+ {
383
+ "Name": "Rust",
384
+ "Type": "Compiled, Curly-bracket, Imperative, Metaprogramming, Procedural",
385
+ "Designed by": "Graydon Hoare"
386
+ },
387
+ {
388
+ "Name": "S",
389
+ "Type": "Array",
390
+ "Designed by": "Rick Becker, Allan Wilks, John Chambers"
391
+ },
392
+ {
393
+ "Name": "S-Lang",
394
+ "Type": "Curly-bracket, Interpreted, Procedural, Scripting, Interactive mode",
395
+ "Designed by": "John E. Davis"
396
+ },
397
+ {
398
+ "Name": "Scala",
399
+ "Type": "Curly-bracket, Interactive mode, Object-oriented class-based",
400
+ "Designed by": "Martin Odersky"
401
+ },
402
+ {
403
+ "Name": "Scheme",
404
+ "Type": "Compiled, Interactive mode, Metaprogramming, Reflective",
405
+ "Designed by": "Guy L. Steele, Gerald Jay Sussman"
406
+ },
407
+ {
408
+ "Name": "Smalltalk",
409
+ "Type": "Compiled, Metaprogramming, Scripting, Interactive mode, Object-oriented class-based, Reflective",
410
+ "Designed by": "Alan Kay, Dan Ingalls, Adele Goldberg"
411
+ },
412
+ {
413
+ "Name": "SQL",
414
+ "Type": "Data-oriented, Declarative, Extension",
415
+ "Designed by": "Donald D. Chamberlin, Raymond F. Boyce"
416
+ },
417
+ {
418
+ "Name": "Swift",
419
+ "Type": "Compiled",
420
+ "Designed by": "Chris Lattner, Apple Inc."
421
+ },
422
+ {
423
+ "Name": "Turing",
424
+ "Type": "Compiled",
425
+ "Designed by": "Ric Holt, James Cordy"
426
+ },
427
+ {
428
+ "Name": "TUTOR",
429
+ "Type": "Authoring",
430
+ "Designed by": "Paul Tenczar, Richard Blomme"
431
+ },
432
+ {
433
+ "Name": "Vala",
434
+ "Type": "Compiled",
435
+ "Designed by": "Jürg Billeter, Raffaele Sandrini"
436
+ },
437
+ {
438
+ "Name": "VBScript",
439
+ "Type": "Interpreted, Procedural, Scripting, Object-oriented class-based",
440
+ "Designed by": "Microsoft"
441
+ },
442
+ {
443
+ "Name": "Visual Basic",
444
+ "Type": "Compiled, Procedural",
445
+ "Designed by": "Microsoft"
446
+ },
447
+ {
448
+ "Name": "Visual FoxPro",
449
+ "Type": "Compiled, Data-oriented, Object-oriented class-based, Procedural",
450
+ "Designed by": "Microsoft"
451
+ },
452
+ {
453
+ "Name": "Windows PowerShell",
454
+ "Type": "Command line interface, Curly-bracket, Interactive mode, Interpreted, Scripting",
455
+ "Designed by": "Microsoft"
456
+ },
457
+ {
458
+ "Name": "X#",
459
+ "Type": "Compiled, Procedural",
460
+ "Designed by": "COSMOS"
461
+ },
462
+ {
463
+ "Name": "X++",
464
+ "Type": "Compiled, Object-oriented class-based, Procedural, Reflective",
465
+ "Designed by": "Microsoft"
466
+ },
467
+ {
468
+ "Name": "X10",
469
+ "Type": "Array, Curly-bracket, Object-oriented class-based, Reflective",
470
+ "Designed by": "Kemal Ebcioglu, Vijay Saraswat, Vivek Sarkar"
471
+ },
472
+ {
473
+ "Name": "XL",
474
+ "Type": "Compiled, Procedural, Reflective, Iterative, Metaprogramming",
475
+ "Designed by": "Christophe de Dinechin"
476
+ },
477
+ {
478
+ "Name": "ZPL",
479
+ "Type": "Array",
480
+ "Designed by": "Chamberlain"
481
+ },
482
+ {
483
+ "Name": "zsh",
484
+ "Type": "Command line interface",
485
+ "Designed by": "Paul Falstad"
486
+ }
487
+ ]
@@ -0,0 +1,41 @@
1
+ RSpec.describe Searchy::Service do
2
+ let!(:data_path) { File.join(File.dirname(__FILE__), '../../spec/fixtures/data.json') }
3
+ let!(:primary_key) { 'Name' }
4
+ let!(:search_fields) { ['Name', 'Type', 'Designed by'] }
5
+
6
+ subject { Searchy::Service.new(data_path: data_path, primary_key: primary_key, search_fields: search_fields) }
7
+
8
+ describe '#find' do
9
+ context 'Support reverse keywords' do
10
+ it 'finds two languages' do
11
+ result = subject.find('Lisp Common')
12
+
13
+ expect(result).to match_array(['Common Lisp', 'Lisp'])
14
+ end
15
+ end
16
+
17
+ context 'Support exacts matching' do
18
+ it 'finds one language' do
19
+ result = subject.find('"Thomas Eugene"')
20
+
21
+ expect(result).to eq(['BASIC'])
22
+ end
23
+ end
24
+
25
+ context 'Support negative searching' do
26
+ it 'finds result' do
27
+ result = subject.find('"Thomas Eugene"')
28
+
29
+ expect(result).to eq(['BASIC'])
30
+ end
31
+ end
32
+
33
+ # context 'Support different fields' do
34
+ # it 'finds result' do
35
+ # result = subject.find('"Thomas Eugene"')
36
+
37
+ # expect(result).to eq(['BASIC'])
38
+ # end
39
+ # end
40
+ end
41
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ require 'pry'
3
+ require 'searchy'
4
+
5
+ RSpec.configure do |config|
6
+ config.order = :random
7
+ config.filter_run focus: true
8
+ config.run_all_when_everything_filtered = true
9
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: searchy-json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - bezrukavyi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.48.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.48.0
83
+ description: Search in JSON file
84
+ email:
85
+ - yaroslav.bezrukavyi@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/searchy.rb
103
+ - lib/searchy/data.rb
104
+ - lib/searchy/extracter.rb
105
+ - lib/searchy/query.rb
106
+ - lib/searchy/service.rb
107
+ - lib/searchy/version.rb
108
+ - searchy.gemspec
109
+ - spec/fixtures/data.json
110
+ - spec/searchy/service_spec.rb
111
+ - spec/spec_helper.rb
112
+ homepage: https://github.com/bezrukavyi/searchy-json
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubygems_version: 3.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Searchy Json
135
+ test_files: []