flexi-json 0.2.0 → 0.4.0

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: f80c4f6ead357e1dfb161b0dc6cca110858e7698b4f8cd875bc40e16d0cade14
4
- data.tar.gz: a66e1baae920f9e1e2c0a6ab2d448e35a71a1a8d337519ad5cd625cda6eefa69
3
+ metadata.gz: 4e8c41b6f187468d64f2d6d3321f7557a5ec17410a69508b8cc1391560ab81be
4
+ data.tar.gz: 5b7aeb733149ae14bce5481878566a99b4a971232900285153278f11d74decf8
5
5
  SHA512:
6
- metadata.gz: a47e6dfe5515d08453ff79d78b224b0c4037450bc3c808e28d214b65c783fc57a46bd7282a4689c692de80fecb23fda6ff582b65988b432116de415a684a9898
7
- data.tar.gz: da908945d06dd9a524587ec7665a14e061db30241defca07e882b7a7bac9d3943e2461a283034bba46c099a04bf29ce207218896ddeb940f924965a59fea55cb
6
+ metadata.gz: 717ae733016f7913d3ef4d2d8d065fbded43304ff3f62b45ede49abf1aed3de63144202fd17bd8e12e4fa0bde1b9c22067027a6f66f873201ce5f30434f9843d
7
+ data.tar.gz: f08b3a2418807a5afce6e2b2c30db6e142829ff2c6fbe11968376f0612e8d6cc5a92315a8e98b377fb49c983d3229ca40ec0d3102982d488f0c4ff8e857d84ca
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # Version: 0.3.0 - 2024-09-22
2
+
3
+ * [#10](https://github.com/GD-Personal/flexi-json/pull/10): Release 0.2.0
4
+ * [#11](https://github.com/GD-Personal/flexi-json/pull/11): v0.3.0 - Advanced search
5
+
6
+
7
+ # Version: 0.2.0 - 2024-09-21
8
+
9
+ * [#1](https://github.com/GD-Personal/flexi-json/pull/1): Add support for different data input to the loader
10
+ * [#2](https://github.com/GD-Personal/flexi-json/pull/2): Add the github_changelog_generator gem
11
+ * [#3](https://github.com/GD-Personal/flexi-json/pull/3): Update changelog workflow
12
+ * [#4](https://github.com/GD-Personal/flexi-json/pull/4): Add token
13
+ * [#5](https://github.com/GD-Personal/flexi-json/pull/5): Add token
14
+ * [#6](https://github.com/GD-Personal/flexi-json/pull/6): Rename json_data to datasets
15
+
16
+
1
17
  ## CHANGELOG
2
18
 
3
19
  ## [0.1.0] - 2024-09-20
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- [![Gem Version](https://badge.fury.io/rb/flexi-json.svg)](https://badge.fury.io/rb/flexi-json) [![Github Actions](https://github.com/GD-Personal/flexi-json/actions/workflows/ci.yml/badge.svg)](https://github.com/GD-Personal/flexi-json/actions) [![Maintainability](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/maintainability)](https://codeclimate.com/github/GD-Personal/flexi-json/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/test_coverage)](https://codeclimate.com/github/GD-Personal/flexi-json/test_coverage)
1
+ [![Gem Version](https://img.shields.io/gem/v/flexi-json.svg)](https://rubygems.org/gems/flexi-json)
2
+ [![Github Actions](https://github.com/GD-Personal/flexi-json/actions/workflows/ci.yml/badge.svg)](https://github.com/GD-Personal/flexi-json/actions)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/maintainability)](https://codeclimate.com/github/GD-Personal/flexi-json/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/bd14f8a5a0c7575d2ac2/test_coverage)](https://codeclimate.com/github/GD-Personal/flexi-json/test_coverage)
2
5
 
3
6
  # flexi-json
4
7
 
@@ -30,6 +33,7 @@ flexi_json = Flexi::Json::Run.new("some/path/to/file.json")
30
33
 
31
34
  # Load a raw json data
32
35
  flexi_json = Flexi::Json::Run.new("{\"name\":\"John\",\"address\":\"Sydney Australia\"}")
36
+ # => <Flexi::Json::Run:0x0000ffffa0f5fc58 @datasets=[#<Flexi::Json::Dataset:0x0000ffffa0f5f668 @address="Sydney Australia", @attributes={:name=>"John", :address=>"Sydney Australia"}, @name="John", @searchable_fields=["name", "address"]>]>
33
37
 
34
38
  # Load a json data from aurl
35
39
  flexi_json = Flexi::Json::Run.new("https://raw.githubusercontent.com/GD-Personal/flexi-json/main/spec/data/dataset.json")
@@ -46,8 +50,23 @@ flexi_json.find_duplicates("email")
46
50
  flexi_json.find_duplicates("email,full_name")
47
51
  ```
48
52
 
53
+ ## Advanced search
54
+ ```ruby
55
+ options = {matched_all: true, exact_match: false}
56
+ flexi_json.search({first_name: "john", address: "sydney"}, options)
57
+ # => [#<Flexi::Json::Dataset:0x0000ffffa0f5f668 @address="Sydney Australia", @attributes={:name=>"John", :address=>"Sydney Australia"}, @name="John", @searchable_fields=["name", "address"]>]
58
+ ```
59
+
60
+ ## Configuration
61
+ ```ruby
62
+ Flexi::Json.configure do |config|
63
+ config.exact_match_search = true
64
+ config.match_all_fields = true
65
+ end
66
+ ```
67
+
49
68
  ## TODOS
50
- - Improve search filter by specifying fields to filter from
69
+ - Generate results in json, csv, txt, or output in the console
51
70
  - Add CRUD support to the dataset
52
71
  - Optimise the search function by implementing indeces
53
72
  - Optimise the loader by chunking the data
@@ -0,0 +1,29 @@
1
+ changelog_type: 'commit_message' # or 'pull_request'
2
+ header_prefix: 'Version:'
3
+ commit_changelog: true
4
+ comment_changelog: true
5
+ include_unlabeled_changes: true
6
+ unlabeled_group_title: 'Unlabeled Changes'
7
+ pull_request_title_regex: '^Release'
8
+ version_regex: 'v?([0-9]{1,2})+[.]+([0-9]{1,2})+[.]+([0-9]{1,2})\s\(\d{1,2}-\d{1,2}-\d{4}\)'
9
+ exclude_labels:
10
+ - bot
11
+ - dependabot
12
+ - ci
13
+ group_config:
14
+ - title: Bug Fixes
15
+ labels:
16
+ - bug
17
+ - bugfix
18
+ - title: Code Improvements
19
+ labels:
20
+ - improvements
21
+ - enhancement
22
+ - title: New Features
23
+ labels:
24
+ - feature
25
+ - title: Documentation Updates
26
+ labels:
27
+ - docs
28
+ - documentation
29
+ - doc
@@ -0,0 +1,26 @@
1
+ require "singleton"
2
+ module Flexi
3
+ module Json
4
+ class ConfigError < StandardError; end
5
+
6
+ class Configuration
7
+ include Singleton
8
+
9
+ attr_accessor :exact_match_search, :match_all_fields
10
+
11
+ class << self
12
+ def default_match_options
13
+ {
14
+ match_all: @match_all_fields || false,
15
+ exact_match: @exact_match_search || false
16
+ }.freeze
17
+ end
18
+ end
19
+
20
+ def initialize
21
+ @exact_match_search = false
22
+ @match_all_fields = false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -5,7 +5,6 @@ module Flexi
5
5
 
6
6
  def initialize(attributes = {})
7
7
  @attributes = attributes
8
-
9
8
  @attributes.each do |key, value|
10
9
  validate_key(key)
11
10
  set_instance_variable(key, value)
@@ -13,15 +12,20 @@ module Flexi
13
12
  end
14
13
  end
15
14
 
16
- # Returns true if any of the client's fields match the search query
17
- def matches?(query, fields = searchable_fields)
18
- valid_fields = fields&.select { |field| searchable_fields.include?(field) } || searchable_fields
15
+ def matches?(query, fields = searchable_fields, options: Flexi::Json::Configuration.default_match_options)
16
+ validateable_fields = query.is_a?(Hash) ? query.keys.map(&:to_s) : fields
17
+ valid_fields = validateable_fields&.select { |field| searchable_fields.include?(field) } || searchable_fields
19
18
 
20
19
  return false if valid_fields.empty?
21
20
 
22
- valid_fields.any? do |field|
23
- value = send(field)
24
- value.to_s.downcase.include?(query.to_s.downcase)
21
+ matching_method = options[:match_all] ? :all? : :any?
22
+ valid_fields.public_send(matching_method) do |field|
23
+ search_query = query.is_a?(Hash) ? query[field.to_sym] : query
24
+ if options[:exact_match]
25
+ attributes[field.to_sym].to_s.downcase == search_query.to_s.downcase
26
+ else
27
+ attributes[field.to_sym].to_s.downcase.include?(search_query.to_s.downcase)
28
+ end
25
29
  end
26
30
  end
27
31
 
@@ -3,7 +3,7 @@ require "json"
3
3
  module Flexi
4
4
  module Json
5
5
  class Searcher
6
- attr_reader :data
6
+ attr_reader :data, :result
7
7
 
8
8
  def initialize(data)
9
9
  @data = data
@@ -11,7 +11,7 @@ module Flexi
11
11
  end
12
12
 
13
13
  def search(query, fields = nil)
14
- @data.select { |data| data.matches?(query, fields) }
14
+ @result = @data.select { |data| data.matches?(query, fields) }
15
15
  end
16
16
 
17
17
  def find_duplicates(keys)
@@ -28,11 +28,11 @@ module Flexi
28
28
  duplicates[key] = value if value.size > 1
29
29
  end
30
30
 
31
- duplicates.values.flatten
31
+ @result = duplicates.values.flatten
32
32
  end
33
33
 
34
34
  # Displays results to the console
35
- def display_results(results, output = $stdout)
35
+ def display_results(results = @result, output = $stdout)
36
36
  if results.empty?
37
37
  output.puts "No data found."
38
38
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Flexi
4
4
  module Json
5
- VERSION = "0.2.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
data/lib/flexi/json.rb CHANGED
@@ -1,25 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "json/configuration"
3
4
  require_relative "json/dataset"
4
5
  require_relative "json/loader"
5
6
  require_relative "json/searcher"
6
7
  require_relative "json/version"
7
8
 
8
9
  module Flexi::Json
9
- class Error < StandardError; end
10
+ class << self
11
+ attr_writer :configuration
12
+
13
+ # Access or initialize the configuration object
14
+ def configuration
15
+ @configuration ||= Flexi::Json::Configuration.instance
16
+ end
17
+
18
+ # Configure block for setting custom configurations
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
10
23
 
11
24
  class Run
12
25
  # Your code goes here...
13
26
  def initialize(data)
14
- @json_data = Flexi::Json::Loader.new(data).load_data
27
+ datasets = Flexi::Json::Loader.new(data).load_data
28
+ @searcher = Flexi::Json::Searcher.new(datasets)
15
29
  end
16
30
 
17
31
  def search(query = "", fields = nil)
18
- Flexi::Json::Searcher.new(@json_data).search(query, fields)
32
+ @searcher.search(query, fields)
19
33
  end
20
34
 
21
35
  def find_duplicates(keys)
22
- Flexi::Json::Searcher.new(@json_data).find_duplicates(keys)
36
+ @searcher.find_duplicates(keys)
23
37
  end
24
38
  end
25
39
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexi-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerda Decio
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-20 00:00:00.000000000 Z
11
+ date: 2024-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundle-audit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: rspec
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +95,19 @@ dependencies:
67
95
  - !ruby/object:Gem::Version
68
96
  version: 0.1.4
69
97
  - !ruby/object:Gem::Dependency
70
- name: github_changelog_generator
98
+ name: debug
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: 1.16.4
103
+ version: 1.9.2
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: 1.16.4
110
+ version: 1.9.2
83
111
  description: A versatile Ruby gem designed for manipulating JSON data. With functionalities
84
112
  for searching, generating new JSON, and transforming existing structures.
85
113
  email:
@@ -95,7 +123,9 @@ files:
95
123
  - LICENSE.txt
96
124
  - README.md
97
125
  - Rakefile
126
+ - changelog_config.yml
98
127
  - lib/flexi/json.rb
128
+ - lib/flexi/json/configuration.rb
99
129
  - lib/flexi/json/dataset.rb
100
130
  - lib/flexi/json/loader.rb
101
131
  - lib/flexi/json/searcher.rb
@@ -106,10 +136,11 @@ licenses:
106
136
  - MIT
107
137
  metadata:
108
138
  allowed_push_host: https://rubygems.org
139
+ bug_tracker_uri: https://github.com/GD-Personal/flexi-json/issues
109
140
  homepage_uri: https://github.com/GD-Personal/flexi-json
110
141
  source_code_uri: https://github.com/GD-Personal/flexi-json
111
142
  changelog_uri: https://github.com/GD-Personal/flexi-json/blob/main/CHANGELOG.md
112
- post_install_message:
143
+ post_install_message:
113
144
  rdoc_options: []
114
145
  require_paths:
115
146
  - lib
@@ -117,15 +148,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
148
  requirements:
118
149
  - - ">="
119
150
  - !ruby/object:Gem::Version
120
- version: 3.0.0
151
+ version: 3.2.2
121
152
  required_rubygems_version: !ruby/object:Gem::Requirement
122
153
  requirements:
123
154
  - - ">="
124
155
  - !ruby/object:Gem::Version
125
156
  version: '0'
126
157
  requirements: []
127
- rubygems_version: 3.5.14
128
- signing_key:
158
+ rubygems_version: 3.5.16
159
+ signing_key:
129
160
  specification_version: 4
130
161
  summary: A ruby gem designed for manipulating JSON data.
131
162
  test_files: []