qig 0.1.3 → 0.2.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: 2e8273358c4ab9ad0e950da9bcd3bfd960478765fecbb846f2aa56959a6d00a4
4
- data.tar.gz: 63fcfe26d488d3aaefa6b83aafd9a9d60f572f40d2b75aec1c0054c55b082fb4
3
+ metadata.gz: baaf3d2d15ea2c35ff975d3b1f373b307269ca866faed4363ffc5648320c415f
4
+ data.tar.gz: 195d83a355ddcf760fd66afb6e3e791b0571d48f01190c9e15fd5b890b83b937
5
5
  SHA512:
6
- metadata.gz: 4a10bd2f7bca3953c74385c3704846c92380eddd7f6524dea68f5abd81a9bdcc37281b3e5e4b1a9c7adfa77113d781dbe3ab699119cd6fe461913c478ba49448
7
- data.tar.gz: 9881a37fdd709fbc51329bf1c15c254ac2c1fffcd4c5e504025268209ab94641df0da7a898a97dda12355961c6f61f30ae67a18912bc7add1c4c01d7c53ce3a8
6
+ metadata.gz: 1124ac020d0e6ad9c8b6be999d8d25c1b1423e5482bcab1c24d832724d566e7783ad1c8780cf7dbf2e84b41e68bc92652896ec1d94f88ef903da267447d2d273
7
+ data.tar.gz: 946766e1e920e92226c5994efb64a435da1c42dbe132b26116bf3065f9f1f77c3d2612eaeb812fa8cda5d9318ea432cf4ed3ba61daeda00e19c322f951a7e4b0
data/.rubocop.yml CHANGED
@@ -1,5 +1,12 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.6
3
+ NewCops: enable
3
4
 
4
5
  Layout/LineLength:
5
6
  Max: 120
7
+
8
+ Metrics/BlockLength:
9
+ IgnoredMethods: ['describe', 'context']
10
+
11
+ Style/DocumentationMethod:
12
+ Enabled: true
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # 0.2.0 (January 14, 2022)
2
+
3
+ ## Features
4
+
5
+ - Value iteration(`[]` over hashes)
6
+
7
+ ## Documentation
8
+
9
+ - Initial yard documentation on method and module
10
+ - Document and spec that we can qig into Structs and OpenStructs
11
+
12
+ # 0.1.3 (January 13, 2022)
13
+
14
+ ## Documentation
15
+
16
+ - fix changelog uri (again)
17
+
18
+ # 0.1.2 (January 13, 2022)
19
+
20
+ ## Documentation
21
+
22
+ - fix changelog uri
23
+
1
24
  # 0.1.1 (January 13, 2022)
2
25
 
3
26
  ## Documentation
data/Gemfile CHANGED
@@ -5,10 +5,11 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in qig.gemspec
6
6
  gemspec
7
7
 
8
+ gem 'pry', '~> 0.14.1'
8
9
  gem 'rake', '~> 13.0'
9
-
10
10
  gem 'rspec', '~> 3.0'
11
-
11
+ gem 'rspec_junit_formatter', '~> 0.5.1'
12
12
  gem 'rubocop', '~> 1.21'
13
-
14
- gem "pry", "~> 0.14.1"
13
+ gem 'rubocop-rake', '~> 0.6.0'
14
+ gem 'rubocop-rspec', '~> 2.7'
15
+ gem 'yard', '~> 0.9.27'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- qig (0.1.3)
4
+ qig (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,6 +33,8 @@ GEM
33
33
  diff-lcs (>= 1.2.0, < 2.0)
34
34
  rspec-support (~> 3.10.0)
35
35
  rspec-support (3.10.3)
36
+ rspec_junit_formatter (0.5.1)
37
+ rspec-core (>= 2, < 4, != 2.12.0)
36
38
  rubocop (1.24.1)
37
39
  parallel (~> 1.10)
38
40
  parser (>= 3.0.0.0)
@@ -44,8 +46,15 @@ GEM
44
46
  unicode-display_width (>= 1.4.0, < 3.0)
45
47
  rubocop-ast (1.15.1)
46
48
  parser (>= 3.0.1.1)
49
+ rubocop-rake (0.6.0)
50
+ rubocop (~> 1.0)
51
+ rubocop-rspec (2.7.0)
52
+ rubocop (~> 1.19)
47
53
  ruby-progressbar (1.11.0)
48
54
  unicode-display_width (2.1.0)
55
+ webrick (1.7.0)
56
+ yard (0.9.27)
57
+ webrick (~> 1.7.0)
49
58
 
50
59
  PLATFORMS
51
60
  x86_64-linux
@@ -55,7 +64,11 @@ DEPENDENCIES
55
64
  qig!
56
65
  rake (~> 13.0)
57
66
  rspec (~> 3.0)
67
+ rspec_junit_formatter (~> 0.5.1)
58
68
  rubocop (~> 1.21)
69
+ rubocop-rake (~> 0.6.0)
70
+ rubocop-rspec (~> 2.7)
71
+ yard (~> 0.9.27)
59
72
 
60
73
  BUNDLED WITH
61
74
  2.3.4
data/README.md CHANGED
@@ -1,16 +1,19 @@
1
1
  # Qig
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/qig.svg)](https://badge.fury.io/rb/qig)
4
+ [![CircleCI](https://circleci.com/gh/NAR8789/qig-ruby/tree/main.svg?style=shield)](https://circleci.com/gh/NAR8789/qig-ruby/tree/main)
5
+
3
6
  qig is dig extended with jq's "value iterator" `[]` operator.
4
7
 
5
8
  ## Features
6
9
 
7
10
  - [x] qig into arrays and hashes
8
- - [ ] qig into structs
9
- - [ ] qig into OpenStructs
11
+ - [x] qig into structs
12
+ - [x] qig into OpenStructs
10
13
  - [ ] qig into CSV::Tables
11
14
  - [ ] qig into CSV::Rows
12
15
  - [x] value iteration over arrays
13
- - [ ] value iteration over hashes
16
+ - [x] value iteration over hashes
14
17
  - [ ] option to monkey patch this for more dig-like `subject.qig(*path)` syntax
15
18
 
16
19
  ## Installation
data/bin/console CHANGED
@@ -7,5 +7,5 @@ require 'qig'
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
- require "pry"
10
+ require 'pry'
11
11
  Pry.start
data/lib/qig/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Qig
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/qig.rb CHANGED
@@ -2,39 +2,45 @@
2
2
 
3
3
  require_relative 'qig/version'
4
4
 
5
+ # Combining the powers of `dig` and `jq`.
6
+ # Qig is dig extended with jq's value iteration `[]` operator.
5
7
  module Qig
6
- def self.qig(*args)
7
- unit_qig(*args)
8
- end
8
+ class << self
9
+ # @param subject [Array, Hash, #[]] `subject` to be qug into.
10
+ # @param path [Array<String, Symbol, Array, Object>] retrieval path to apply to `subject`
11
+ #
12
+ # @return [Object, Array<Object>] the value(s) of `subject` located at `path`
13
+ def qig(subject, *path)
14
+ unit_qig(subject, *path)
15
+ end
9
16
 
10
- def self.unit_qig(subject, *path)
11
- return subject if subject.nil?
17
+ private
12
18
 
13
- head, *rest = path
14
- case head
15
- when nil
16
- subject
17
- when []
18
- collection_qig(subject, *rest)
19
- # hmm... what should happen if I [] on something not an array?
20
- else
21
- unit_qig(subject[head], *rest)
19
+ def unit_qig(subject, *path)
20
+ head, *rest = path
21
+ case head
22
+ when nil
23
+ subject
24
+ when []
25
+ subject = subject&.values if subject.is_a? Hash
26
+ collection_qig(subject, *rest)
27
+ else
28
+ unit_qig(subject&.[](head), *rest)
29
+ end
22
30
  end
23
- end
24
-
25
- def self.collection_qig(subjects, *path)
26
- return subjects if subjects.empty?
27
31
 
28
- head, *rest = path
29
- case head
30
- when nil
31
- subjects
32
- when []
33
- collection_qig(subjects.flatten(1), *rest)
34
- # not sure this is quite jq-compliant... [] refuses to iterate over atoms, but flatten will just preserve them.
35
- # maybe more in the spirit of `dig` though?
36
- else
37
- collection_qig(subjects.map { |e| e.nil? ? e : e[head] }, *rest)
32
+ def collection_qig(subjects, *path)
33
+ head, *rest = path
34
+ case head
35
+ when nil
36
+ subjects
37
+ when []
38
+ collection_qig(subjects.map { |s| s.is_a?(Hash) ? s.values : s }.flatten(1), *rest)
39
+ # not sure this is quite jq-compliant... [] refuses to iterate over atoms, but flatten will just preserve them.
40
+ # maybe more in the spirit of `dig` though?
41
+ else
42
+ collection_qig(subjects.map { |e| e.nil? ? e : e[head] }, *rest)
43
+ end
38
44
  end
39
45
  end
40
46
  end
data/qig.gemspec CHANGED
@@ -34,4 +34,5 @@ Gem::Specification.new do |spec|
34
34
 
35
35
  # For more information and examples about making a new gem, check out our
36
36
  # guide at: https://bundler.io/guides/creating_gem.html
37
+ spec.metadata['rubygems_mfa_required'] = 'true'
37
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Fan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-13 00:00:00.000000000 Z
11
+ date: 2022-01-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -19,6 +19,7 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - ".rspec"
21
21
  - ".rubocop.yml"
22
+ - ".yardopts"
22
23
  - CHANGELOG.md
23
24
  - CODE_OF_CONDUCT.md
24
25
  - Gemfile
@@ -39,6 +40,7 @@ metadata:
39
40
  homepage_uri: https://github.com/NAR8789/qig-ruby
40
41
  source_code_uri: https://github.com/NAR8789/qig-ruby
41
42
  changelog_uri: https://github.com/NAR8789/qig-ruby/blob/main/CHANGELOG.md
43
+ rubygems_mfa_required: 'true'
42
44
  post_install_message:
43
45
  rdoc_options: []
44
46
  require_paths: