jini 0.0.1 → 0.0.2
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 +4 -4
- data/.yardoc/checksums +1 -0
- data/.yardoc/complete +0 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Gemfile +3 -1
- data/README.md +2 -3
- data/doc/Jini/InvalidPath.html +135 -0
- data/doc/Jini.html +1280 -0
- data/doc/_index.html +122 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +497 -0
- data/doc/file.README.html +99 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +99 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +139 -0
- data/doc/top-level-namespace.html +110 -0
- data/jini.gemspec +1 -1
- data/jini.iml +6 -1
- data/lib/jini.rb +79 -1
- data/test/jini_test.rb +77 -13
- data/test/test_helper.rb +31 -0
- metadata +23 -2
- data/lib/main.rb +0 -13
data/lib/jini.rb
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# (The MIT License)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2022-2022 Ivanchuk Ivan
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
# copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
# SOFTWARE.
|
|
24
|
+
|
|
3
25
|
# It's a simple XPATH builder.
|
|
4
26
|
# require 'jini'
|
|
5
27
|
# xpath = Jini.new('body')
|
|
@@ -10,41 +32,97 @@ class Jini
|
|
|
10
32
|
# When path not valid
|
|
11
33
|
class InvalidPath < StandardError; end
|
|
12
34
|
|
|
35
|
+
# @param head [String] with head of your xpath
|
|
13
36
|
def initialize(head = '')
|
|
14
37
|
@head = head
|
|
15
38
|
end
|
|
16
39
|
|
|
17
40
|
# Convert it to a string.
|
|
41
|
+
# @return [String] xpath as string
|
|
18
42
|
def to_s
|
|
19
43
|
@head.to_s
|
|
20
44
|
end
|
|
21
45
|
|
|
22
46
|
# Additional node for xpath.
|
|
47
|
+
# @param node [String] node
|
|
48
|
+
# @return [Jini] object
|
|
23
49
|
def add_path(node)
|
|
24
50
|
Jini.new("#{@head}/#{node}")
|
|
25
51
|
end
|
|
26
52
|
|
|
27
53
|
# Additional attribute for xpath.
|
|
54
|
+
# [@key="value"]
|
|
55
|
+
# @param key [String] name of attr
|
|
56
|
+
# @param value [String] value of attr
|
|
57
|
+
# @return [Jini] object
|
|
28
58
|
def add_attr(key, value)
|
|
29
59
|
Jini.new("#{@head}[@#{key}=\"#{value}\"]")
|
|
30
60
|
end
|
|
31
61
|
|
|
62
|
+
# Adds an @value to xpath
|
|
63
|
+
# @param value [String] with value attr
|
|
64
|
+
# @return [Jini] object
|
|
32
65
|
def all_attr(value)
|
|
33
66
|
Jini.new("#{@head}@#{value}")
|
|
34
67
|
end
|
|
35
68
|
|
|
36
69
|
# Xpath with all elements.
|
|
70
|
+
# Addition a *** to xpath
|
|
71
|
+
# @return [Jini] object
|
|
37
72
|
def all
|
|
38
|
-
|
|
73
|
+
raise InvalidPath, 'You cannot add all tag after attr!' if @head[-1].eql?(']')
|
|
74
|
+
Jini.new(add_path('*').to_s) unless @head[-1].eql?(']')
|
|
39
75
|
end
|
|
40
76
|
|
|
41
77
|
# Xpath with all named elements.
|
|
78
|
+
# Addition _//node_ to xpath
|
|
79
|
+
# @param node [String] name of node
|
|
80
|
+
# @return [Jini] object
|
|
42
81
|
def add_all(node)
|
|
43
82
|
Jini.new("#{@head}//#{node}")
|
|
44
83
|
end
|
|
45
84
|
|
|
46
85
|
# Access by index.
|
|
86
|
+
# Addition _[index]_ to xpath
|
|
87
|
+
# @param position [Integer] number
|
|
88
|
+
# @return [Jini] object
|
|
47
89
|
def at(position)
|
|
48
90
|
Jini.new("#{@head}[#{position}]")
|
|
49
91
|
end
|
|
92
|
+
|
|
93
|
+
# Replace all _/_ to _::_ symbols
|
|
94
|
+
# if path doesn't contain invalid symbols for selection
|
|
95
|
+
# @return [Jini] selection
|
|
96
|
+
def selection
|
|
97
|
+
if @head.include?('[') || @head.include?(']') || @head.include?('@')
|
|
98
|
+
raise InvalidPath, 'Cannot select, path contains bad symbols'
|
|
99
|
+
end
|
|
100
|
+
Jini.new(@head.gsub('/', '::').to_s)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Removes node by name
|
|
104
|
+
# @param node [String] name of node for removal
|
|
105
|
+
# @return [Jini] without a node
|
|
106
|
+
def remove_path(node)
|
|
107
|
+
copy = @head
|
|
108
|
+
Jini.new(copy.gsub("/#{node}", ''))
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Removes attr by name
|
|
112
|
+
# before:
|
|
113
|
+
# /parent/child[@k="v"]
|
|
114
|
+
# .remove_attr('k')
|
|
115
|
+
# after:
|
|
116
|
+
# /parent/child
|
|
117
|
+
# @param [String] name of attr
|
|
118
|
+
# @return [Jini] without an attr
|
|
119
|
+
def remove_attr(name)
|
|
120
|
+
Jini.new(
|
|
121
|
+
@head
|
|
122
|
+
.gsub(
|
|
123
|
+
/(\[@|#{name}="[^"]+"|[]+|])/,
|
|
124
|
+
''
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
end
|
|
50
128
|
end
|
data/test/jini_test.rb
CHANGED
|
@@ -1,22 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# (The MIT License)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2022-2022 Ivanchuk Ivan
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
# copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
# SOFTWARE.
|
|
24
|
+
|
|
1
25
|
require_relative '../lib/jini'
|
|
2
26
|
require 'minitest/autorun'
|
|
3
|
-
|
|
27
|
+
require_relative 'test_helper'
|
|
28
|
+
|
|
29
|
+
# Jini test.
|
|
30
|
+
# Author:: Ivan Ivanchuk (clicker.heroes.acg@gmail.com)
|
|
31
|
+
# Copyright:: Copyright (c) 2022-2022 Ivan Ivanchuck
|
|
32
|
+
# License:: MIT
|
|
33
|
+
class JiniTest < Minitest::Test
|
|
34
|
+
def test_add_path_and_at_success
|
|
35
|
+
assert_equal(
|
|
36
|
+
'/parent/child[1]',
|
|
37
|
+
Jini.new
|
|
38
|
+
.add_path('parent')
|
|
39
|
+
.add_path('child')
|
|
40
|
+
.at(1)
|
|
41
|
+
.to_s
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_add_attr_success
|
|
46
|
+
assert_equal(
|
|
47
|
+
'/node[@key="value"]',
|
|
48
|
+
Jini.new
|
|
49
|
+
.add_path('node')
|
|
50
|
+
.add_attr('key', 'value')
|
|
51
|
+
.to_s
|
|
52
|
+
)
|
|
53
|
+
end
|
|
4
54
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
55
|
+
def test_all_success
|
|
56
|
+
assert_equal(
|
|
57
|
+
'/parent/child/*',
|
|
58
|
+
Jini.new
|
|
59
|
+
.add_path('parent')
|
|
60
|
+
.add_path('child')
|
|
61
|
+
.all
|
|
62
|
+
.to_s
|
|
63
|
+
)
|
|
8
64
|
end
|
|
9
65
|
|
|
10
|
-
def
|
|
11
|
-
|
|
66
|
+
def test_all_fail
|
|
67
|
+
assert_raises do
|
|
68
|
+
Jini.new
|
|
69
|
+
.add_path('parent')
|
|
70
|
+
.add_attr('key', 'value')
|
|
71
|
+
.all
|
|
72
|
+
end
|
|
12
73
|
end
|
|
13
74
|
|
|
14
|
-
def
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
75
|
+
def test_remove_attr_success
|
|
76
|
+
assert_equal(
|
|
77
|
+
'/home/batya',
|
|
78
|
+
Jini.new
|
|
79
|
+
.add_path('home')
|
|
80
|
+
.add_path('batya')
|
|
81
|
+
.add_attr('drunk', 'very')
|
|
82
|
+
.remove_attr('drunk')
|
|
83
|
+
.to_s
|
|
84
|
+
)
|
|
21
85
|
end
|
|
22
86
|
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright (c) 2022-2022 Ivan Ivanchuk
|
|
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 all
|
|
13
|
+
# 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 NONINFINGEMENT. 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 THE
|
|
21
|
+
# SOFTWARE.
|
|
22
|
+
|
|
23
|
+
$stdout.sync = true
|
|
24
|
+
|
|
25
|
+
require 'simplecov'
|
|
26
|
+
|
|
27
|
+
SimpleCov.start
|
|
28
|
+
if ENV['CI'] == 'true'
|
|
29
|
+
require 'codecov'
|
|
30
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
|
31
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jini
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ivan Ivanchuck
|
|
@@ -63,13 +63,34 @@ extra_rdoc_files:
|
|
|
63
63
|
files:
|
|
64
64
|
- ".gitignore"
|
|
65
65
|
- ".rubocop.yml"
|
|
66
|
+
- ".yardoc/checksums"
|
|
67
|
+
- ".yardoc/complete"
|
|
68
|
+
- ".yardoc/object_types"
|
|
69
|
+
- ".yardoc/objects/root.dat"
|
|
70
|
+
- ".yardoc/proxy_types"
|
|
66
71
|
- Gemfile
|
|
67
72
|
- README.md
|
|
73
|
+
- doc/Jini.html
|
|
74
|
+
- doc/Jini/InvalidPath.html
|
|
75
|
+
- doc/_index.html
|
|
76
|
+
- doc/class_list.html
|
|
77
|
+
- doc/css/common.css
|
|
78
|
+
- doc/css/full_list.css
|
|
79
|
+
- doc/css/style.css
|
|
80
|
+
- doc/file.README.html
|
|
81
|
+
- doc/file_list.html
|
|
82
|
+
- doc/frames.html
|
|
83
|
+
- doc/index.html
|
|
84
|
+
- doc/js/app.js
|
|
85
|
+
- doc/js/full_list.js
|
|
86
|
+
- doc/js/jquery.js
|
|
87
|
+
- doc/method_list.html
|
|
88
|
+
- doc/top-level-namespace.html
|
|
68
89
|
- jini.gemspec
|
|
69
90
|
- jini.iml
|
|
70
91
|
- lib/jini.rb
|
|
71
|
-
- lib/main.rb
|
|
72
92
|
- test/jini_test.rb
|
|
93
|
+
- test/test_helper.rb
|
|
73
94
|
homepage: https://github.com/l3r8yJ/jini
|
|
74
95
|
licenses:
|
|
75
96
|
- MIT
|
data/lib/main.rb
DELETED