jini 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 79847e73810a2cf8deffac608a6f3f212dc5eddf7b3eaf56e541b96ad6677658
4
+ data.tar.gz: 2ee14cc1e0f17e9fd3a08ff4dd4e35a179d545257bf57bb0af340ee6cca51e6f
5
+ SHA512:
6
+ metadata.gz: 96929a0c9277a3fdd9e6d35370fac58c745ba946afe5afb5961f6bf7122afd4a77dd6247292a2680cbb2b5886b6ff9276b90fc6218f0e59493fc995ef73c50bb
7
+ data.tar.gz: 3949cfb950a3f2457c4fb7e49ea8c5cc90c117ad3b4f344516313e7843eb0fc62c9e501e5886f0b8aac7fcf0f15d782a137ad2f1d8ffa16defe9efdb683ed518
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ Gemfile.lock
2
+ *.gem
3
+ .bundle/
4
+ .DS_Store
5
+ rdoc/
6
+ .idea/
7
+ coverage/
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.2
4
+ SuggestExtensions: false
5
+ NewCops: enable
6
+
7
+ Metrics/ClassLength:
8
+ Exclude:
9
+ - 'test/*.rb'
10
+ Layout/EmptyLineAfterGuardClause:
11
+ Enabled: false
12
+ Layout/MultilineMethodCallIndentation:
13
+ Enabled: false
14
+ Metrics/AbcSize:
15
+ Max: 30
16
+ Metrics/MethodLength:
17
+ Max: 30
18
+ Metrics/CyclomaticComplexity:
19
+ Max: 12
20
+ Metrics/PerceivedComplexity:
21
+ Max: 12
22
+ Layout/EndOfLine:
23
+ EnforcedStyle: lf
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'minitest', '5.16.1'
8
+ gem 'minitest-reporters'
9
+ end
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ The class [`Jini`](https://www.rubydoc.info/github/yegor256/iri/master/Iri)
2
+ helps you build a XPATH.
3
+
4
+ ```ruby
5
+ require 'jini'
6
+ xpath = Jini
7
+ .new
8
+ .add_path('parent') # addition a path node
9
+ .add_path('child') # addition a path node
10
+ .add_attr('key', 'value') # addition an attribute
11
+ .to_s # convert it to a string
12
+ # -> xpath: parent/child[@key="value"]
13
+ ```
14
+
15
+ The full list of methods is [here](https://www.rubydoc.info/github/l3r8y/jini/master/Jini).
16
+
17
+ Install it:
18
+
19
+ ```bash
20
+ $ gem install jini
21
+ ```
22
+
23
+ Or add this to your `Gemfile`:
24
+
25
+ ```bash
26
+ gem 'jini'
27
+ ```
28
+
29
+ Pay attention, it is not a parser. The only functionality this gem provides
30
+ is _building_ XPATHs.
data/jini.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ Gem::Specification.new do |s|
5
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
6
+ s.required_ruby_version = '>=3.0.0'
7
+ s.name = 'jini'
8
+ s.version = '0.0.1'
9
+ s.license = 'MIT'
10
+ s.summary = 'Simple Immutable Ruby XPATH Builder'
11
+ s.description = 'Class Jini helps you build a XPATH and then modify its \
12
+ parts via a simple fluent interface.'
13
+ s.authors = ['Ivan Ivanchuck']
14
+ s.email = 'clicker.heroes.acg@gmail.com'
15
+ s.homepage = 'https://github.com/l3r8yJ/jini'
16
+ s.files = `git ls-files`.split($RS)
17
+ s.rdoc_options = ['--charset=UTF-8']
18
+ s.extra_rdoc_files = ['README.md']
19
+ s.add_development_dependency 'minitest', '5.16.3'
20
+ s.add_development_dependency 'rubocop', '1.31.1'
21
+ s.add_development_dependency 'rubocop-rspec', '2.11.1'
22
+ s.metadata = { 'rubygems_mfa_required' => 'true' }
23
+ end
data/jini.iml ADDED
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
7
+ </content>
8
+ <orderEntry type="inheritedJdk" />
9
+ <orderEntry type="sourceFolder" forTests="false" />
10
+ <orderEntry type="library" scope="PROVIDED" name="ansi (v1.5.0, RVM: ruby-3.0.0) [gem]" level="application" />
11
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-3.0.0) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-3.0.0) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.22, RVM: ruby-3.0.0) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, RVM: ruby-3.0.0) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.16.1, RVM: ruby-3.0.0) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="minitest-reporters (v1.5.0, RVM: ruby-3.0.0) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, RVM: ruby-3.0.0) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.1, RVM: ruby-3.0.0) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-3.0.0) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.5.0, RVM: ruby-3.0.0) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, RVM: ruby-3.0.0) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.31.1, RVM: ruby-3.0.0) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.21.0, RVM: ruby-3.0.0) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v2.11.1, RVM: ruby-3.0.0) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, RVM: ruby-3.0.0) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.3.0, RVM: ruby-3.0.0) [gem]" level="application" />
27
+ </component>
28
+ </module>
data/lib/jini.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # It's a simple XPATH builder.
4
+ # require 'jini'
5
+ # xpath = Jini.new('body')
6
+ # .add_path(node: 'child')
7
+ # .add_path(node: 'child')
8
+ # .to_s // /body/child/child
9
+ class Jini
10
+ # When path not valid
11
+ class InvalidPath < StandardError; end
12
+
13
+ def initialize(head = '')
14
+ @head = head
15
+ end
16
+
17
+ # Convert it to a string.
18
+ def to_s
19
+ @head.to_s
20
+ end
21
+
22
+ # Additional node for xpath.
23
+ def add_path(node)
24
+ Jini.new("#{@head}/#{node}")
25
+ end
26
+
27
+ # Additional attribute for xpath.
28
+ def add_attr(key, value)
29
+ Jini.new("#{@head}[@#{key}=\"#{value}\"]")
30
+ end
31
+
32
+ def all_attr(value)
33
+ Jini.new("#{@head}@#{value}")
34
+ end
35
+
36
+ # Xpath with all elements.
37
+ def all
38
+ Jini.new(add_path('*').to_s)
39
+ end
40
+
41
+ # Xpath with all named elements.
42
+ def add_all(node)
43
+ Jini.new("#{@head}//#{node}")
44
+ end
45
+
46
+ # Access by index.
47
+ def at(position)
48
+ Jini.new("#{@head}[#{position}]")
49
+ end
50
+ end
data/lib/main.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jini'
4
+
5
+ def test
6
+ xpath = Jini.new('head')
7
+ .add_path('parent') # addition a path node
8
+ .add_path('child') # addition a path node
9
+ .add_attr('key', 'value')
10
+ print xpath.to_s
11
+ end
12
+
13
+ test
data/test/jini_test.rb ADDED
@@ -0,0 +1,22 @@
1
+ require_relative '../lib/jini'
2
+ require 'minitest/autorun'
3
+ require 'minitest/reporters'
4
+
5
+ class JiniTest < Minitest::Unit
6
+ def setup
7
+ # Do nothing
8
+ end
9
+
10
+ def teardown
11
+ # Do nothing
12
+ end
13
+
14
+ def test
15
+ xpath = Jini
16
+ .new
17
+ .add_path('parent')
18
+ .add_path('child')
19
+ .at(1)
20
+ assert_equal('/parent/child[1]', xpath.to_s)
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jini
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Ivanchuck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 5.16.3
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 5.16.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.31.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.31.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.11.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 2.11.1
55
+ description: |-
56
+ Class Jini helps you build a XPATH and then modify its \
57
+ parts via a simple fluent interface.
58
+ email: clicker.heroes.acg@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files:
62
+ - README.md
63
+ files:
64
+ - ".gitignore"
65
+ - ".rubocop.yml"
66
+ - Gemfile
67
+ - README.md
68
+ - jini.gemspec
69
+ - jini.iml
70
+ - lib/jini.rb
71
+ - lib/main.rb
72
+ - test/jini_test.rb
73
+ homepage: https://github.com/l3r8yJ/jini
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ rubygems_mfa_required: 'true'
78
+ post_install_message:
79
+ rdoc_options:
80
+ - "--charset=UTF-8"
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.0.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.3.22
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Simple Immutable Ruby XPATH Builder
98
+ test_files: []