hrr_rb_relaxed_xml 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e982808589429c99bf9aac96fe929d059ba84df2f59244a255c61d8099b8776f
4
+ data.tar.gz: 9fcf8ab9c579e52853cee5b2dfc9784e2ce7d75487dc1142e30dbcfa93b2e7f3
5
+ SHA512:
6
+ metadata.gz: 03a330b02e251177937924a0be0f597775e2c4b1d0c010e8bb059afed6f7d1af0af18330f896d858cdef8e778a89761d5e08256933616e073ae5ddbd2de6bcce
7
+ data.tar.gz: dcdd2b86e705a3ef78abd01382648a6cbc073b3f8b9524364603c7e98b81c83e3aa7da27bd2d48117a7b02582b5629bf2b131358a406c5aef50b613c8dfd7050
data/.gitignore ADDED
@@ -0,0 +1,26 @@
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
24
+ .DS_Store
25
+ *~
26
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,32 @@
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
+ - ruby-head
15
+ os:
16
+ - linux
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: ruby-head
20
+ before_install:
21
+ - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
22
+ - gem install bundler -v '< 2'
23
+ install:
24
+ - bundle install --path vendor/bundle
25
+ before_script:
26
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
27
+ - chmod +x ./cc-test-reporter
28
+ - ./cc-test-reporter before-build
29
+ script:
30
+ - bundle exec rake spec
31
+ after_script:
32
+ - ./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
data/LICENSE.txt ADDED
@@ -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.
data/README.md ADDED
@@ -0,0 +1,138 @@
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`, `#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.elements[1] # => <root1> ... </>
95
+ xml_doc.elements['root1'].elements['child1'] # => <child1> ... </>
96
+ xml_doc.elements['root1'].elements['child1'].root # => <root1> ... </>
97
+
98
+ xml_doc.elements[2] # => <root2> ... </>
99
+ xml_doc.elements['root2'].elements['child2'] # => <child2> ... </>
100
+ xml_doc.elements['root2'].elements['child2'].root # => <root2> ... </>
101
+
102
+ xml_doc.add_element 'root3'
103
+ xml_doc.elements[3] # => <root3> ... </>
104
+
105
+ xml_doc.add REXML::Element.new('root4')
106
+ xml_doc.elements[4] # => <root4> ... </>
107
+ ```
108
+
109
+ hrr_rb_relaxed_xml also supports XPath.
110
+
111
+ ```ruby
112
+ xml_doc.elements['root1'].elements['child1'].xpath # => "/root1/child1"
113
+ xml_doc.elements['root2'].elements['child2'].xpath # => "/root2/child2"
114
+
115
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/*") # => [<root1> ... </>, <root2> ... </>]
116
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root1/../root2") # => [<root2> ... </>]
117
+
118
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root1/child12/following::*") # => [<child13/>, <root2> ... </>, <child21/>, <child22/>, <child23/>]
119
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root1/child12/following-sibling::*") # => [<child13/>]
120
+
121
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root2/child22/preceding::*") # => [<child21/>, <child13/>, <child12/>, <child11/>, <root1> ... </>]
122
+ HrrRbRelaxedXML::XPath.match(xml_doc, "/root2/child22/preceding-sibling::*") # => [<child21/>]
123
+ ```
124
+
125
+
126
+ ## Contributing
127
+
128
+ 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.
129
+
130
+
131
+ ## License
132
+
133
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
134
+
135
+
136
+ ## Code of Conduct
137
+
138
+ 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).
data/Rakefile ADDED
@@ -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,31 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ lib = File.expand_path("../lib", __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "hrr_rb_relaxed_xml/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "hrr_rb_relaxed_xml"
10
+ spec.version = HrrRbRelaxedXML::VERSION
11
+ spec.authors = ["hirura"]
12
+ spec.email = ["hirura@gmail.com"]
13
+
14
+ spec.summary = %q{an REXML-based XML toolkit that can have multiple root elements}
15
+ spec.description = %q{an REXML-based XML toolkit that can have multiple root elements}
16
+ spec.homepage = "https://github.com/hirura/hrr_rb_relaxed_xml"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.required_ruby_version = '>= 2.0.0'
25
+
26
+ spec.add_dependency "rexml"
27
+
28
+ spec.add_development_dependency "rake"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "simplecov"
31
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'rexml/document'
5
+
6
+ module HrrRbRelaxedXML
7
+ class Document < REXML::Document
8
+ def add child
9
+ case child
10
+ when REXML::XMLDecl, REXML::DocType
11
+ super
12
+ else
13
+ child.parent = self
14
+ @children << child
15
+ child
16
+ end
17
+ end
18
+ alias :<< :add
19
+
20
+ def add_element element, attrs={}
21
+ if element.nil?
22
+ super
23
+ else
24
+ child_e = @elements.add element
25
+ attrs.each do |k, v|
26
+ child_e.attributes[k] = v
27
+ end
28
+ child_e
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbRelaxedXML
5
+ VERSION = "0.1.0"
6
+ end
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ require 'rexml/document'
5
+
6
+ module HrrRbRelaxedXML
7
+ class XPath < REXML::XPath
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ # vim: et ts=2 sw=2
3
+
4
+ module HrrRbRelaxedXML
5
+ end
6
+
7
+ require "hrr_rb_relaxed_xml/version"
8
+ require "hrr_rb_relaxed_xml/document"
9
+ require "hrr_rb_relaxed_xml/xpath"
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.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hirura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-08 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.0.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: an REXML-based XML toolkit that can have multiple root elements
112
+ test_files: []