flexi-json 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f80c4f6ead357e1dfb161b0dc6cca110858e7698b4f8cd875bc40e16d0cade14
4
- data.tar.gz: a66e1baae920f9e1e2c0a6ab2d448e35a71a1a8d337519ad5cd625cda6eefa69
3
+ metadata.gz: b10a91e8b4e687fdd0c69e73b8a53d6f1e66e96361fe08259c7244aec87e638b
4
+ data.tar.gz: 2f7a7dd6d9acc9069c3c1884ff98736041113889c8cd35efa5c94bd7f6acd48e
5
5
  SHA512:
6
- metadata.gz: a47e6dfe5515d08453ff79d78b224b0c4037450bc3c808e28d214b65c783fc57a46bd7282a4689c692de80fecb23fda6ff582b65988b432116de415a684a9898
7
- data.tar.gz: da908945d06dd9a524587ec7665a14e061db30241defca07e882b7a7bac9d3943e2461a283034bba46c099a04bf29ce207218896ddeb940f924965a59fea55cb
6
+ metadata.gz: 1f793341d32d74087ce18d669f0df367e1503a081a4e227cb8dbda80e8e3a64fdc02b9bd7324b69738bde9b86aeb6f70c287ea75db0bd3accafff23ea08216b5
7
+ data.tar.gz: dbd6b4bf1f222c4fb657ab346057ae975073397b7c5a4d84c32f0589b02e9c905be510ae6ea10c49b19515a312f19ef950bc64e0573268f80172ca185e8fa896
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
@@ -30,6 +30,7 @@ flexi_json = Flexi::Json::Run.new("some/path/to/file.json")
30
30
 
31
31
  # Load a raw json data
32
32
  flexi_json = Flexi::Json::Run.new("{\"name\":\"John\",\"address\":\"Sydney Australia\"}")
33
+ # => <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
34
 
34
35
  # Load a json data from aurl
35
36
  flexi_json = Flexi::Json::Run.new("https://raw.githubusercontent.com/GD-Personal/flexi-json/main/spec/data/dataset.json")
@@ -46,6 +47,13 @@ flexi_json.find_duplicates("email")
46
47
  flexi_json.find_duplicates("email,full_name")
47
48
  ```
48
49
 
50
+ ## Advanced search
51
+ ```ruby
52
+ options = {matched_all: true, exact_match: false}
53
+ flexi_json.search({first_name: "john", address: "sydney"}, options)
54
+ # => [#<Flexi::Json::Dataset:0x0000ffffa0f5f668 @address="Sydney Australia", @attributes={:name=>"John", :address=>"Sydney Australia"}, @name="John", @searchable_fields=["name", "address"]>]
55
+ ```
56
+
49
57
  ## TODOS
50
58
  - Improve search filter by specifying fields to filter from
51
59
  - Add CRUD support to the dataset
@@ -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
@@ -1,3 +1,4 @@
1
+ require "debug"
1
2
  module Flexi
2
3
  module Json
3
4
  class Dataset
@@ -5,7 +6,6 @@ module Flexi
5
6
 
6
7
  def initialize(attributes = {})
7
8
  @attributes = attributes
8
-
9
9
  @attributes.each do |key, value|
10
10
  validate_key(key)
11
11
  set_instance_variable(key, value)
@@ -13,15 +13,20 @@ module Flexi
13
13
  end
14
14
  end
15
15
 
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
16
+ def matches?(query, fields = searchable_fields, options: Searcher::DEFAULT_MATCH_OPTIONS)
17
+ validateable_fields = query.is_a?(Hash) ? query.keys.map(&:to_s) : fields
18
+ valid_fields = validateable_fields&.select { |field| searchable_fields.include?(field) } || searchable_fields
19
19
 
20
20
  return false if valid_fields.empty?
21
21
 
22
- valid_fields.any? do |field|
23
- value = send(field)
24
- value.to_s.downcase.include?(query.to_s.downcase)
22
+ matching_method = options[:matched_all] ? :all? : :any?
23
+ valid_fields.public_send(matching_method) do |field|
24
+ search_query = query.is_a?(Hash) ? query[field.to_sym] : query
25
+ if options[:exact_match]
26
+ attributes[field.to_sym].to_s.downcase == search_query.to_s.downcase
27
+ else
28
+ attributes[field.to_sym].to_s.downcase.include?(search_query.to_s.downcase)
29
+ end
25
30
  end
26
31
  end
27
32
 
@@ -3,7 +3,12 @@ require "json"
3
3
  module Flexi
4
4
  module Json
5
5
  class Searcher
6
- attr_reader :data
6
+ attr_reader :data, :result
7
+
8
+ DEFAULT_MATCH_OPTIONS = {
9
+ matched_all: false,
10
+ exact_match: false
11
+ }.freeze
7
12
 
8
13
  def initialize(data)
9
14
  @data = data
@@ -11,7 +16,7 @@ module Flexi
11
16
  end
12
17
 
13
18
  def search(query, fields = nil)
14
- @data.select { |data| data.matches?(query, fields) }
19
+ @result = @data.select { |data| data.matches?(query, fields) }
15
20
  end
16
21
 
17
22
  def find_duplicates(keys)
@@ -28,11 +33,11 @@ module Flexi
28
33
  duplicates[key] = value if value.size > 1
29
34
  end
30
35
 
31
- duplicates.values.flatten
36
+ @result = duplicates.values.flatten
32
37
  end
33
38
 
34
39
  # Displays results to the console
35
- def display_results(results, output = $stdout)
40
+ def display_results(results = @result, output = $stdout)
36
41
  if results.empty?
37
42
  output.puts "No data found."
38
43
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Flexi
4
4
  module Json
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
data/lib/flexi/json.rb CHANGED
@@ -11,15 +11,20 @@ module Flexi::Json
11
11
  class Run
12
12
  # Your code goes here...
13
13
  def initialize(data)
14
- @json_data = Flexi::Json::Loader.new(data).load_data
14
+ datasets = Flexi::Json::Loader.new(data).load_data
15
+ @searcher = Flexi::Json::Searcher.new(datasets)
15
16
  end
16
17
 
17
18
  def search(query = "", fields = nil)
18
- Flexi::Json::Searcher.new(@json_data).search(query, fields)
19
+ @searcher.search(query, fields)
19
20
  end
20
21
 
21
22
  def find_duplicates(keys)
22
- Flexi::Json::Searcher.new(@json_data).find_duplicates(keys)
23
+ @searcher.find_duplicates(keys)
24
+ end
25
+
26
+ def display_results
27
+ @searcher.display_results
23
28
  end
24
29
  end
25
30
  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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerda Decio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-20 00:00:00.000000000 Z
11
+ date: 2024-09-21 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,6 +123,7 @@ files:
95
123
  - LICENSE.txt
96
124
  - README.md
97
125
  - Rakefile
126
+ - changelog_config.yml
98
127
  - lib/flexi/json.rb
99
128
  - lib/flexi/json/dataset.rb
100
129
  - lib/flexi/json/loader.rb
@@ -106,6 +135,7 @@ licenses:
106
135
  - MIT
107
136
  metadata:
108
137
  allowed_push_host: https://rubygems.org
138
+ bug_tracker_uri: https://github.com/GD-Personal/flexi-json/issues
109
139
  homepage_uri: https://github.com/GD-Personal/flexi-json
110
140
  source_code_uri: https://github.com/GD-Personal/flexi-json
111
141
  changelog_uri: https://github.com/GD-Personal/flexi-json/blob/main/CHANGELOG.md
@@ -117,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
147
  requirements:
118
148
  - - ">="
119
149
  - !ruby/object:Gem::Version
120
- version: 3.0.0
150
+ version: 3.2.2
121
151
  required_rubygems_version: !ruby/object:Gem::Requirement
122
152
  requirements:
123
153
  - - ">="