hrr_rb_relaxed_xml 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c1c488d30312c198e464d5ff1f0d8cbf12129a3e241cc6ed27db9c505a7bec0
4
+ data.tar.gz: a12a05a8df4405ffbbd2f933435e4af6a90f737cdde4f394454cb3048a0aab63
5
+ SHA512:
6
+ metadata.gz: d9c0e87cf5dd1db798d299f04ea27f11939c37ee126da927a87d5bcebd781c0049a405d9df5b317fef527bf86aec4130b71a10c0486542ec7e95acc994047a05
7
+ data.tar.gz: f6c9a48003c40ab2b8cc8301366603c4815f02f78844063c32dac2e0b462cb14e17db8aac8a24e5c6bedd0ab4c3de1c003fc515708c304d8b2fc0cf48a495c19
@@ -0,0 +1,23 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ ## Environment normalization:
14
+ /vendor/bundle
15
+ /lib/bundler/man/
16
+
17
+ # for a library or gem, you might want to ignore these files since the code is
18
+ # intended to run in multiple environments; otherwise, check them in:
19
+ Gemfile.lock
20
+ .ruby-version
21
+ .ruby-gemset
22
+
23
+ # additional
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,33 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=a08f0fdd362fbc73dc1cc976890a4ecf1c0f13f996945bccd9b807d1550cc8fe
4
+ sudo: false
5
+ language: ruby
6
+ rvm:
7
+ - 2.0
8
+ - 2.1
9
+ - 2.2
10
+ - 2.3
11
+ - 2.4
12
+ - 2.5
13
+ - 2.6
14
+ - 2.7
15
+ - ruby-head
16
+ os:
17
+ - linux
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: ruby-head
21
+ before_install:
22
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
23
+ - gem install bundler -v '< 2'
24
+ install:
25
+ - bundle install --path vendor/bundle
26
+ before_script:
27
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
28
+ - chmod +x ./cc-test-reporter
29
+ - ./cc-test-reporter before-build
30
+ script:
31
+ - bundle exec rake spec
32
+ after_script:
33
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hirura@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in hrr_rb_relaxed_xml.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 hirura
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.
@@ -0,0 +1,140 @@
1
+ # HrrRbRelaxedXML
2
+
3
+ [![Build Status](https://travis-ci.org/hirura/hrr_rb_relaxed_xml.svg?branch=master)](https://travis-ci.org/hirura/hrr_rb_relaxed_xml)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/4575e959b53a447b5fa6/maintainability)](https://codeclimate.com/github/hirura/hrr_rb_relaxed_xml/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/4575e959b53a447b5fa6/test_coverage)](https://codeclimate.com/github/hirura/hrr_rb_relaxed_xml/test_coverage)
6
+ [![Gem Version](https://badge.fury.io/rb/hrr_rb_relaxed_xml.svg)](https://badge.fury.io/rb/hrr_rb_relaxed_xml)
7
+
8
+ hrr_rb_relaxed_xml is an REXML-based XML toolkit that can have multiple root elements.
9
+
10
+
11
+ ## Table of Contents
12
+
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ - [Contributing](#contributing)
16
+ - [License](#license)
17
+ - [Code of Conduct](#code-of-conduct)
18
+
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'hrr_rb_relaxed_xml'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ ```sh
31
+ $ bundle
32
+ ```
33
+
34
+ Or install it yourself as:
35
+
36
+ ```sh
37
+ $ gem install hrr_rb_relaxed_xml
38
+ ```
39
+
40
+
41
+ ## Usage
42
+
43
+ First of all, hrr_rb_relaxed_xml library needs to be loaded.
44
+
45
+ ```ruby
46
+ require 'hrr_rb_relaxed_xml'
47
+ ```
48
+
49
+ hrr_rb_relaxed_xml supports tree parsing of an XML document that has multiple root elements.
50
+
51
+ ```ruby
52
+ xml_doc = HrrRbRelaxedXML::Document.new <<-EOB
53
+ <root1>
54
+ <child11 />
55
+ <child12 />
56
+ <child13 />
57
+ </root1>
58
+ <root2>
59
+ <child21 />
60
+ <child22 />
61
+ <child23 />
62
+ </root2>
63
+ EOB
64
+ ```
65
+
66
+ Then, any methods that are supported by REXML can be performed.
67
+
68
+ `#write` method outputs an XML that contains all root elements.
69
+
70
+ ```ruby
71
+ xml_doc.write(STDOUT, 2)
72
+ ```
73
+
74
+ The output of the `#write` method is the below.
75
+
76
+ ```
77
+ <root1>
78
+ <child11 />
79
+ <child12 />
80
+ <child13 />
81
+ </root1>
82
+ <root2>
83
+ <child21 />
84
+ <child22 />
85
+ <child23 />
86
+ </root2>
87
+ ```
88
+
89
+ With using `#elements`, `#clone`, `#deep_clone`, `#root`, `#add_element`, or `#add` methods, the XML document can be manipulated.
90
+
91
+ ```ruby
92
+ xml_doc.elements.to_a # => [<root1> ... </>, <root2> ... </>]
93
+
94
+ xml_doc.deep_clone.elements.to_a # => [<root1> ... </>, <root2> ... </>]
95
+
96
+ xml_doc.elements[1] # => <root1> ... </>
97
+ xml_doc.elements['root1'].elements['child1'] # => <child1> ... </>
98
+ xml_doc.elements['root1'].elements['child1'].root # => <root1> ... </>
99
+
100
+ xml_doc.elements[2] # => <root2> ... </>
101
+ xml_doc.elements['root2'].elements['child2'] # => <child2> ... </>
102
+ xml_doc.elements['root2'].elements['child2'].root # => <root2> ... </>
103
+
104
+ xml_doc.add_element 'root3'
105
+ xml_doc.elements[3] # => <root3> ... </>
106
+
107
+ xml_doc.add REXML::Element.new('root4')
108
+ xml_doc.elements[4] # => <root4> ... </>
109
+ ```
110
+
111
+ hrr_rb_relaxed_xml also supports XPath.
112
+
113
+ ```ruby
114
+ xml_doc.elements['root1'].elements['child1'].xpath # => "/root1/child1"
115
+ xml_doc.elements['root2'].elements['child2'].xpath # => "/root2/child2"
116
+
117
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/*") # => [<root1> ... </>, <root2> ... </>]
118
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root1/../root2") # => [<root2> ... </>]
119
+
120
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root1/child12/following::*") # => [<child13/>, <root2> ... </>, <child21/>, <child22/>, <child23/>]
121
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root1/child12/following-sibling::*") # => [<child13/>]
122
+
123
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root2/child22/preceding::*") # => [<child21/>, <child13/>, <child12/>, <child11/>, <root1> ... </>]
124
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root2/child22/preceding-sibling::*") # => [<child21/>]
125
+ ```
126
+
127
+
128
+ ## Contributing
129
+
130
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hirura/hrr_rb_relaxed_xml. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
131
+
132
+
133
+ ## License
134
+
135
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
136
+
137
+
138
+ ## Code of Conduct
139
+
140
+ Everyone interacting in the hrr_rb_relaxed_xml project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hirura/hrr_rb_relaxed_xml/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "hrr_rb_relaxed_xml/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hrr_rb_relaxed_xml"
7
+ spec.version = HrrRbRelaxedXML::VERSION
8
+ spec.authors = ["hirura"]
9
+ spec.email = ["hirura@gmail.com"]
10
+
11
+ spec.summary = %q{An REXML-based XML toolkit that can have multiple root elements}
12
+ spec.description = %q{An REXML-based XML toolkit that can have multiple root elements}
13
+ spec.homepage = "https://github.com/hirura/hrr_rb_relaxed_xml"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.0.0'
22
+
23
+ spec.add_dependency "rexml"
24
+
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "simplecov"
28
+ end
@@ -0,0 +1,6 @@
1
+ module HrrRbRelaxedXML
2
+ end
3
+
4
+ require "hrr_rb_relaxed_xml/version"
5
+ require "hrr_rb_relaxed_xml/document"
6
+ require "hrr_rb_relaxed_xml/xpath"
@@ -0,0 +1,32 @@
1
+ require 'rexml/document'
2
+
3
+ module HrrRbRelaxedXML
4
+ class Document < REXML::Document
5
+ def clone
6
+ self.class.new self
7
+ end
8
+
9
+ def add child
10
+ case child
11
+ when REXML::XMLDecl, REXML::DocType
12
+ super
13
+ else
14
+ child.parent = self
15
+ @children << child
16
+ child
17
+ end
18
+ end
19
+ alias :<< :add
20
+
21
+ def add_element element, attrs={}
22
+ case element
23
+ when nil
24
+ super
25
+ else
26
+ child_e = @elements.add element
27
+ child_e.add_attributes attrs
28
+ child_e
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module HrrRbRelaxedXML
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'rexml/document'
2
+
3
+ module HrrRbRelaxedXML
4
+ class XPath < REXML::XPath
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hrr_rb_relaxed_xml
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - hirura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rexml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: An REXML-based XML toolkit that can have multiple root elements
70
+ email:
71
+ - hirura@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - hrr_rb_relaxed_xml.gemspec
85
+ - lib/hrr_rb_relaxed_xml.rb
86
+ - lib/hrr_rb_relaxed_xml/document.rb
87
+ - lib/hrr_rb_relaxed_xml/version.rb
88
+ - lib/hrr_rb_relaxed_xml/xpath.rb
89
+ homepage: https://github.com/hirura/hrr_rb_relaxed_xml
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 2.0.0
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.1.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: An REXML-based XML toolkit that can have multiple root elements
112
+ test_files: []