xml_tree_viewer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +188 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/xml_tree_viewer.rb +204 -0
- data/lib/xml_tree_viewer/version.rb +5 -0
- data/xml_tree_viewer.gemspec +38 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fec47a35be5340bc08e8ad3670cfed606befde86d0c21ea5d4bc38194bb0d54a
|
4
|
+
data.tar.gz: 3cfd775fe766ab4f36e02fc00003cac0315fb7dc3c62443f1234317d71b06351
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 016f87f336ad2c083bc943b7294526a8074534f3ece828ddc02f0c9fe00cfe367913136bc469b493d8b19a69b96e383e97243248f7d5a905c10fc6f2bcb47b43
|
7
|
+
data.tar.gz: 361308b6a1b87ee9a73699490df99b619399de1136f1785dea1e638e30016a1a708563ae09b94f2f8a7b1cf2cebf94853cd5ce300b94c9fe247eca2b1fc573c7
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hello@13plus4.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
xml_tree_viewer (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
parallel (1.20.1)
|
11
|
+
parser (3.0.1.1)
|
12
|
+
ast (~> 2.4.1)
|
13
|
+
rainbow (3.0.0)
|
14
|
+
rake (13.0.3)
|
15
|
+
regexp_parser (2.1.1)
|
16
|
+
rexml (3.2.5)
|
17
|
+
rubocop (1.17.0)
|
18
|
+
parallel (~> 1.10)
|
19
|
+
parser (>= 3.0.0.0)
|
20
|
+
rainbow (>= 2.2.2, < 4.0)
|
21
|
+
regexp_parser (>= 1.8, < 3.0)
|
22
|
+
rexml
|
23
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
24
|
+
ruby-progressbar (~> 1.7)
|
25
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
26
|
+
rubocop-ast (1.7.0)
|
27
|
+
parser (>= 3.0.1.1)
|
28
|
+
ruby-progressbar (1.11.0)
|
29
|
+
unicode-display_width (2.0.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
x86_64-darwin-20
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
rake (~> 13.0)
|
36
|
+
rubocop (~> 1.7)
|
37
|
+
xml_tree_viewer!
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
2.2.19
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 a6b8
|
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
|
13
|
+
all 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 NONINFRINGEMENT. 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
<a href="#table-of-contents">
|
2
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/Headline.svg" height="55px" name="XML Tree Viewer" alt="# Xml Tree Viewer">
|
3
|
+
</a>
|
4
|
+
|
5
|
+
A .xml string will do up to a easy readable tree strcuture for terminal output.
|
6
|
+
|
7
|
+
<br>
|
8
|
+
<br>
|
9
|
+
<a href="#table-of-contents">
|
10
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/examples.svg" height="55px" name="examples" alt="Examples">
|
11
|
+
</a>
|
12
|
+
|
13
|
+
|
14
|
+
### Detail
|
15
|
+
**Code**
|
16
|
+
```ruby
|
17
|
+
require 'xml_tree_viewer'
|
18
|
+
xml = XmlTreeViewer.helper()
|
19
|
+
XmlTreeViewer.generate( xml, :detail )
|
20
|
+
```
|
21
|
+
**Output**
|
22
|
+
```txt
|
23
|
+
TREE OVERVIEW
|
24
|
+
employees
|
25
|
+
doc.css('employees')
|
26
|
+
┗━ employee
|
27
|
+
doc.css('employees > employee:nth-of-type(1)')
|
28
|
+
┗━ fullname
|
29
|
+
doc.css('employees > employee:nth-of-type(1) > fullname')
|
30
|
+
┗━ employee
|
31
|
+
doc.css('employees > employee:nth-of-type(2)')
|
32
|
+
┗━ fullname
|
33
|
+
doc.css('employees > employee:nth-of-type(2) > fullname')
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
### Short
|
38
|
+
**Code**
|
39
|
+
```ruby
|
40
|
+
require 'xml_tree_viewer'
|
41
|
+
xml = XmlTreeViewer.helper()
|
42
|
+
XmlTreeViewer.generate( xml, :short )
|
43
|
+
```
|
44
|
+
|
45
|
+
**Output**
|
46
|
+
```txt
|
47
|
+
TREE OVERVIEW
|
48
|
+
employees
|
49
|
+
┗━ employee
|
50
|
+
┗━ fullname
|
51
|
+
┗━ employee
|
52
|
+
┗━ fullname
|
53
|
+
```
|
54
|
+
<br>
|
55
|
+
<br>
|
56
|
+
<br>
|
57
|
+
<a href="#table-of-contents">
|
58
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/table-of-contents.svg" height="55px" name="table-of-contents" alt="Table of Contents">
|
59
|
+
</a>
|
60
|
+
<br>
|
61
|
+
|
62
|
+
1. [Quickstart](#quickstart)<br>
|
63
|
+
2. [Parameters](#parameters)<br>
|
64
|
+
3. [Contributing](#contributing)<br>
|
65
|
+
4. [Limitations](#limitations)<br>
|
66
|
+
5. [Credits](#credits)<br>
|
67
|
+
6. [License](#license)<br>
|
68
|
+
7. [Code of Conduct](#code-of-conduct)<br>
|
69
|
+
8. [Support my Work](#support-my-work)<br>
|
70
|
+
|
71
|
+
<br>
|
72
|
+
<br>
|
73
|
+
<a href="#table-of-contents">
|
74
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/quickstart.svg" height="55px" name="quickstart" alt="Quickstart">
|
75
|
+
</a>
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
require '../lib/xml_tree_viewer'
|
79
|
+
|
80
|
+
xml = XmlTreeViewer.helper()
|
81
|
+
XmlTreeViewer.generate( xml, :detail )
|
82
|
+
```
|
83
|
+
<br>
|
84
|
+
<br>
|
85
|
+
<a href="#table-of-contents">
|
86
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/local-path-builder-for-ruby/readme/headlines/setup.svg" height="55px" name="setup" alt="Setup">
|
87
|
+
</a>
|
88
|
+
|
89
|
+
Add this line to your application's Gemfile:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
gem 'xml_tree_viewer'
|
93
|
+
```
|
94
|
+
|
95
|
+
And then execute:
|
96
|
+
|
97
|
+
$ bundle install
|
98
|
+
|
99
|
+
Or install it yourself as:
|
100
|
+
|
101
|
+
$ gem install xml_tree_viewer
|
102
|
+
|
103
|
+
|
104
|
+
On Rubygems:
|
105
|
+
- Gem: https://rubygems.org/gems/xml_tree_viewer
|
106
|
+
- Profile: https://rubygems.org/profiles/a6b8
|
107
|
+
|
108
|
+
<br>
|
109
|
+
<br>
|
110
|
+
<a href="#table-of-contents">
|
111
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/methods.svg" height="55px" name="methods" alt="Methods">
|
112
|
+
</a>
|
113
|
+
|
114
|
+
### .helper()
|
115
|
+
```ruby
|
116
|
+
xml = XmlTreeViewer.helper()
|
117
|
+
```
|
118
|
+
|
119
|
+
### .generate()
|
120
|
+
```ruby
|
121
|
+
XmlTreeViewer.generate(
|
122
|
+
xml,
|
123
|
+
mode
|
124
|
+
)
|
125
|
+
```
|
126
|
+
|
127
|
+
|
128
|
+
**Input**
|
129
|
+
| **Type** | **Required** | **Description** | **Example** | **Description** |
|
130
|
+
|------:|:------|:------|:------|:------|
|
131
|
+
| **xml** | ```String``` | Yes | "Test" | Define path structure |
|
132
|
+
| **mode** | ```Symbol``` | Yes | ```:detail``` | Set console mode. Use ```:detail```, ```:short``` or ```:silent``` |
|
133
|
+
|
134
|
+
**Return**<br>
|
135
|
+
Boolean
|
136
|
+
|
137
|
+
<br>
|
138
|
+
<br>
|
139
|
+
<a href="#table-of-contents">
|
140
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/contributing.svg" height="55px" name="contributing" alt="Contributing">
|
141
|
+
</a>
|
142
|
+
|
143
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/a6b8/xml-tree-viewer-for-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/a6b8/xml-tree-viewer-for-ruby/blob/master/CODE_OF_CONDUCT.md).
|
144
|
+
<br>
|
145
|
+
<br>
|
146
|
+
<br>
|
147
|
+
<a href="#table-of-contents">
|
148
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/limitations.svg" height="55px" name="limitations" alt="Limitations">
|
149
|
+
</a>
|
150
|
+
- Tested for Rss and Atom Feeds.
|
151
|
+
<br>
|
152
|
+
<br>
|
153
|
+
|
154
|
+
<a href="#table-of-contents">
|
155
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/credits.svg" height="55px" name="credits" alt="Credits">
|
156
|
+
</a>
|
157
|
+
|
158
|
+
This gem depend on following gems:
|
159
|
+
|
160
|
+
- nokogiri<br>
|
161
|
+
https://rubygems.org/gems/nokogiri
|
162
|
+
|
163
|
+
- active_support<br>
|
164
|
+
https://rubygems.org/gems/activesupport
|
165
|
+
|
166
|
+
<br>
|
167
|
+
<br>
|
168
|
+
<a href="#table-of-contents">
|
169
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/license.svg" height="55px" name="license" alt="License">
|
170
|
+
</a>
|
171
|
+
|
172
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
173
|
+
<br>
|
174
|
+
<br>
|
175
|
+
<br>
|
176
|
+
<a href="#table-of-contents">
|
177
|
+
<img src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/code-of-conduct.svg" height="55px" name="code-of-conduct" alt="Code of Conduct">
|
178
|
+
</a>
|
179
|
+
|
180
|
+
Everyone interacting in the xml-tree-viewer-for-ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a6b8/xml-tree-viewer-for-ruby/blob/master/CODE_OF_CONDUCT.md).
|
181
|
+
<br>
|
182
|
+
<br>
|
183
|
+
<br>
|
184
|
+
<a href="#table-of-contents">
|
185
|
+
<img href="#table-of-contents" src="https://raw.githubusercontent.com/a6b8/a6b8/main/docs/xml-tree-viewer-for-ruby/readme/headlines/support-my-work.svg" height="55px" name="support-my-work" alt="Support my Work">
|
186
|
+
</a>
|
187
|
+
|
188
|
+
Donate by [https://www.paypal.com](https://www.paypal.com/donate?hosted_button_id=XKYLQ9FBGC4RG)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "xml_tree_viewer"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'net/http'
|
4
|
+
require "active_support/core_ext/hash/indifferent_access"
|
5
|
+
|
6
|
+
require_relative "xml_tree_viewer/version"
|
7
|
+
|
8
|
+
|
9
|
+
module XmlTreeViewer
|
10
|
+
class Error < StandardError; end
|
11
|
+
def self.helper()
|
12
|
+
result = <<-EOXML
|
13
|
+
<employees>
|
14
|
+
<employee status="active">
|
15
|
+
<fullname>John Doe</fullname>
|
16
|
+
</employee>
|
17
|
+
<employee status="inactive">
|
18
|
+
<fullname>Max Mustermann</fullname>
|
19
|
+
</employee>
|
20
|
+
</employees>
|
21
|
+
EOXML
|
22
|
+
return result
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def self.generate( xml, mode )
|
27
|
+
|
28
|
+
if validate( xml, mode )
|
29
|
+
self.draw_xml( xml, mode )
|
30
|
+
end
|
31
|
+
|
32
|
+
return true
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
|
39
|
+
def self.validate( xml, mode )
|
40
|
+
messages = {
|
41
|
+
xml: [],
|
42
|
+
mode: []
|
43
|
+
}
|
44
|
+
|
45
|
+
if xml.class.to_s.eql?( 'String' )
|
46
|
+
doc = Nokogiri::XML( xml )
|
47
|
+
if doc.errors.length == 0
|
48
|
+
|
49
|
+
else
|
50
|
+
messages[:xml].push( 'XML is not valid')
|
51
|
+
end
|
52
|
+
else
|
53
|
+
messages[:xml].push( 'Is not Type "String"' )
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
if mode.class.to_s.eql?( 'Symbol' )
|
58
|
+
if [ :silent, :short, :detail].include?( mode )
|
59
|
+
|
60
|
+
else
|
61
|
+
messages[:mode].push( "\":#{mode}\" is not authorized, please use :silent, :short or :detail instead.")
|
62
|
+
end
|
63
|
+
else
|
64
|
+
messages[:mode].push( 'Is not Type "Symbol"')
|
65
|
+
end
|
66
|
+
|
67
|
+
valid = messages.keys.map { | key | messages[ key ].length }.sum == 0
|
68
|
+
|
69
|
+
if !valid
|
70
|
+
puts 'Following errors occured:'
|
71
|
+
messages.keys.each do | key |
|
72
|
+
if messages[ key ].length != 0
|
73
|
+
puts " #{key[ 0, 1 ].upcase}#{key[ 1, key.length ]}"
|
74
|
+
messages[ key ].each do | m |
|
75
|
+
puts " - #{m}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
return valid
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def self.is_url?( str )
|
86
|
+
begin
|
87
|
+
uri = URI.parse str
|
88
|
+
uri.kind_of? URI::HTTP
|
89
|
+
rescue URI::InvalidURIError
|
90
|
+
false
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
def self.draw_xml( xml, mode )
|
96
|
+
def self.draw_hash_line_edge( l, type, offset )
|
97
|
+
str = ''
|
98
|
+
|
99
|
+
for i in 1..( ( l - 1 ) * offset )
|
100
|
+
str += ' '
|
101
|
+
end
|
102
|
+
|
103
|
+
case type
|
104
|
+
when :edge
|
105
|
+
if l > 1
|
106
|
+
str += "┗"
|
107
|
+
str += "━"
|
108
|
+
str += " "
|
109
|
+
else
|
110
|
+
str += ' '
|
111
|
+
end
|
112
|
+
when :empty
|
113
|
+
str += ' '
|
114
|
+
end
|
115
|
+
|
116
|
+
return str
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def self.draw_hash_line( name, mode, offset, key )
|
121
|
+
lines = []
|
122
|
+
if !mode.eql?( :silent )
|
123
|
+
level = name[ 1, name.length ].to_i
|
124
|
+
|
125
|
+
str = ''
|
126
|
+
edge = self.draw_hash_line_edge( level, :edge, offset )
|
127
|
+
str = "#{edge} #{key.name}"
|
128
|
+
lines.push( str )
|
129
|
+
|
130
|
+
case mode
|
131
|
+
when :short
|
132
|
+
when :detail
|
133
|
+
empty = self.draw_hash_line_edge( level, :empty, offset )
|
134
|
+
str = "#{empty} doc.css('#{key.css_path}')"
|
135
|
+
lines.push( str )
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
return lines
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
struct = Nokogiri::XML( xml )
|
144
|
+
types = [ Hash, ActiveSupport::HashWithIndifferentAccess ]
|
145
|
+
offset = 4
|
146
|
+
|
147
|
+
lines = []
|
148
|
+
!mode.eql?( :silent ) ? lines += [ 'TREE OVERVIEW' ] : ''
|
149
|
+
|
150
|
+
struct.element_children.each do | l1 |
|
151
|
+
lines += self.draw_hash_line( 'l1', mode, offset, l1 )
|
152
|
+
l1.element_children.each do | l2 |
|
153
|
+
lines += self.draw_hash_line( 'l2', mode, offset, l2 )
|
154
|
+
l2.element_children.each do | l3 |
|
155
|
+
lines += self.draw_hash_line( 'l3', mode, offset, l3 )
|
156
|
+
l3.element_children.each do | l4 |
|
157
|
+
lines += self.draw_hash_line( 'l4', mode, offset, l4 )
|
158
|
+
l4.element_children.each do | l5 |
|
159
|
+
lines += self.draw_hash_line( 'l5', mode, offset, l5 )
|
160
|
+
l5.element_children.each do | l6 |
|
161
|
+
lines += self.draw_hash_line( 'l6', mode, offset, l6 )
|
162
|
+
l6.element_children.each do | l7 |
|
163
|
+
lines += self.draw_hash_line( 'l7', mode, offset, l7 )
|
164
|
+
l7.element_children.each do | l8 |
|
165
|
+
lines += self.draw_hash_line( 'l8', mode, offset, l8 )
|
166
|
+
l8.element_children.each do | l9 |
|
167
|
+
lines += self.draw_hash_line( 'l9', mode, offset, l9 )
|
168
|
+
l9.element_children.each do | l10 |
|
169
|
+
lines += self.draw_hash_line( 'l10', mode, offset, l10 )
|
170
|
+
l10.element_children.each do | l11 |
|
171
|
+
lines += self.draw_hash_line( 'l11', mode, offset, l11 )
|
172
|
+
l11.element_children.each do | l12 |
|
173
|
+
lines += self.draw_hash_line( 'l12', mode, offset, l12 )
|
174
|
+
l12.element_children.each do | l13 |
|
175
|
+
lines += self.draw_hash_line( 'l13', mode, offset, l13 )
|
176
|
+
l13.element_children.each do | l14 |
|
177
|
+
lines += self.draw_hash_line( 'l14', mode, offset, l14 )
|
178
|
+
l14.element_children.each do | l15 |
|
179
|
+
lines += self.draw_hash_line( 'l15', mode, offset, l15 )
|
180
|
+
'...'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
if !mode.eql?( :silent )
|
198
|
+
lines.each { | line | puts( line ) }
|
199
|
+
end
|
200
|
+
|
201
|
+
return true
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/xml_tree_viewer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "xml_tree_viewer"
|
7
|
+
spec.version = XmlTreeViewer::VERSION
|
8
|
+
spec.authors = ["a6b8"]
|
9
|
+
spec.email = ["hello@13plus4.com"]
|
10
|
+
|
11
|
+
spec.summary = "A .xml string will do up to a easy readable tree strcuture."
|
12
|
+
spec.description = "A .xml string will do up to a easy readable tree strcuture for terminal output."
|
13
|
+
spec.homepage = "https://github.com/a6b8/xml-tree-viewer-for-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/a6b8/xml-tree-viewer-for-ruby"
|
21
|
+
spec.metadata["changelog_uri"] = "https://raw.githubusercontent.com/a6b8/xml-tree-viewer-for-ruby/main/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
spec.add_dependency "nokogiri", "~> 1.11"
|
34
|
+
|
35
|
+
spec
|
36
|
+
# For more information and examples about making a new gem, checkout our
|
37
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xml_tree_viewer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- a6b8
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
description: A .xml string will do up to a easy readable tree strcuture for terminal
|
28
|
+
output.
|
29
|
+
email:
|
30
|
+
- hello@13plus4.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- lib/xml_tree_viewer.rb
|
47
|
+
- lib/xml_tree_viewer/version.rb
|
48
|
+
- xml_tree_viewer.gemspec
|
49
|
+
homepage: https://github.com/a6b8/xml-tree-viewer-for-ruby
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata:
|
53
|
+
allowed_push_host: https://rubygems.org
|
54
|
+
homepage_uri: https://github.com/a6b8/xml-tree-viewer-for-ruby
|
55
|
+
source_code_uri: https://github.com/a6b8/xml-tree-viewer-for-ruby
|
56
|
+
changelog_uri: https://raw.githubusercontent.com/a6b8/xml-tree-viewer-for-ruby/main/CHANGELOG.md
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.4.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.2.3
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: A .xml string will do up to a easy readable tree strcuture.
|
76
|
+
test_files: []
|