sixarm_ruby_xml_load 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # SixArm.com » Ruby » <br> XML#load methods to load documents, elements, attributes
2
+
3
+ * Docs: <http://sixarm.com/sixarm_ruby_week/doc>
4
+ * Repo: <http://github.com/sixarm/sixarm_ruby_week>
5
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
6
+
7
+
8
+ ## Introduction
9
+
10
+ XML load methods:
11
+
12
+ * XML.load_dir: load XML documents from one or more directory paths and file paths.
13
+ * XML.load_elements: load XML elements from a file and with an xpath selector.
14
+ * XML.load_attributes: load XML attributes from a file and with an xpath selector.
15
+ * XML.load_attributes_array: load XML attributes into an array
16
+ * XML.load_attributes_hash: load XML attributes into a hash of name value pairs.
17
+
18
+ For docs go to <http://sixarm.com/sixarm_ruby_week/doc>
19
+
20
+ Want to help? We're happy to get pull requests.
21
+
22
+
23
+ ## Quickstart
24
+
25
+ Install:
26
+
27
+ gem install sixarm_xml_load
28
+
29
+ Bundler:
30
+
31
+ gem "sixarm_ruby_xml_load", "=2.1.0"
32
+
33
+ Require:
34
+
35
+ require "sixarm_ruby_xml_load"
36
+
37
+
38
+ ## High Security (Optional)
39
+
40
+ To enable high security for all our gems:
41
+
42
+ wget http://sixarm.com/sixarm.pem
43
+ gem cert --add sixarm.pem
44
+ gem sources --add http://sixarm.com
45
+
46
+ To install with high security:
47
+
48
+ gem install sixarm_ruby_alpha_bravo --test --trust-policy HighSecurity
49
+
50
+
51
+ ## Changes
52
+
53
+ * 2012-03-16 2.1.0 Upgrade for Ruby 1.9.3, minitest/spec, and improved docs.
54
+ * 2012-03-13 2.0.0 Lift the XML#load methods from the sixarm_ruby_ramp gem
55
+
56
+
57
+ ## License
58
+
59
+ You may choose any of these open source licenses:
60
+
61
+ * Apache License
62
+ * BSD License
63
+ * CreativeCommons License, Non-commercial Share Alike
64
+ * GNU General Public License Version 2 (GPL 2)
65
+ * GNU Lesser General Public License (LGPL)
66
+ * MIT License
67
+ * Perl Artistic License
68
+ * Ruby License
69
+
70
+ The software is provided "as is", without warranty of any kind,
71
+ express or implied, including but not limited to the warranties of
72
+ merchantability, fitness for a particular purpose and noninfringement.
73
+
74
+ In no event shall the authors or copyright holders be liable for any
75
+ claim, damages or other liability, whether in an action of contract,
76
+ tort or otherwise, arising from, out of or in connection with the
77
+ software or the use or other dealings in the software.
78
+
79
+ This license is for the included software that is created by SixArm;
80
+ some of the included software may have its own licenses, copyrights,
81
+ authors, etc. and these do take precedence over the SixArm license.
82
+
83
+ Copyright (c) 2005-2013 Joel Parker Henderson
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
@@ -0,0 +1,87 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README
4
+ =end
5
+
6
+ require 'sixarm_ruby_rexml'
7
+
8
+ module XML
9
+
10
+
11
+ # Specify one or more directory patterns and pass each XML file in the matching directories to a block.
12
+ #
13
+ # See [Dir#glob](http://www.ruby-doc.org/core/classes/Dir.html#M002347) for pattern details.
14
+ #
15
+ # @example To load xml documents
16
+ # XML.load_dir('/tmp/*.xml'){|xml_document|
17
+ # #...whatever you want to do with each xml document
18
+ # }
19
+ #
20
+ # @example To load xml documents in files beginning in "foo" or "bar"
21
+ # XML.load_dir('/tmp/foo*.yaml','/tmp/bar*.xml','){|xml_document|
22
+ # #...whatever you want to do with the xml document
23
+ # }
24
+
25
+ def XML.load_dir(*dirpaths)
26
+ dirpaths=[*dirpaths.flatten]
27
+ dirpaths.each do |dirpath|
28
+ Dir[dirpath].sort.each do |filename|
29
+ File.open(filename) do |file|
30
+ doc = REXML::Document.new file
31
+ yield doc
32
+ end #file
33
+ end #dir
34
+ end #each
35
+ end #def
36
+
37
+
38
+ # Sugar to load elements from a file.
39
+ #
40
+ # @example
41
+ # XML.load_elements('config.xml','userlist/user'){|element| pp element.attributes['first_name'] }
42
+
43
+ def XML.load_elements(dirpath,xpath)
44
+ XML.load_dir(dirpath){|doc|
45
+ doc.elements.each(xpath){|elem|
46
+ yield elem
47
+ }
48
+ }
49
+ end
50
+
51
+
52
+ # Sugar to load attributes from a file.
53
+ #
54
+ # @example
55
+ # XML.load_attributes('config.xml','userlist/user'){|attributes| pp attributes['first_name'] }
56
+
57
+ def XML.load_attributes(dirpath,xpath)
58
+ XML.load_elements(dirpath,xpath){|elem|
59
+ yield elem.attributes
60
+ }
61
+ end
62
+
63
+
64
+ # Sugar to load attributes array from a file.
65
+ #
66
+ # @example
67
+ # XML.load_attributes_array('config.xml','userlist/user'){|attributes| pp attributes['first_name'] }
68
+
69
+ def XML.load_attributes_array(dirpath,xpath)
70
+ XML.load_elements(dirpath,xpath){|elem|
71
+ yield elem.attributes.to_a
72
+ }
73
+ end
74
+
75
+
76
+ # Sugar to load attributes hash from a file.
77
+ #
78
+ # @example
79
+ # XML.load_attributes_hash('config.xml','userlist/user'){|attributes| pp attributes['first_name'] }
80
+
81
+ def XML.load_attributes_hash(dirpath,xpath)
82
+ XML.load_elements(dirpath,xpath){|elem|
83
+ yield elem.attributes.to_a_hash
84
+ }
85
+ end
86
+
87
+ end
@@ -0,0 +1,5 @@
1
+ <foo>
2
+ <bar x="a"/>
3
+ <bar x="b"/>
4
+ <bar x="c"/>
5
+ </foo>
@@ -0,0 +1,5 @@
1
+ <foo>
2
+ <bar x="d"/>
3
+ <bar x="e"/>
4
+ <bar x="f"/>
5
+ </foo>
@@ -0,0 +1,80 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_xml_load'
6
+ require 'pathname'
7
+
8
+ describe XML do
9
+
10
+ before do
11
+ TESTPATH ||= Pathname.new("test/sixarm_ruby_xml_load_test")
12
+ end
13
+
14
+ describe ".load_dir_files" do
15
+
16
+ it "loads" do
17
+ dirpath=TESTPATH + 'test_*.xml'
18
+ expect=[(TESTPATH + 'test_1.xml').to_s, (TESTPATH + 'test_2.xml').to_s]
19
+ actual=Dir[dirpath].sort
20
+ actual.must_equal expect
21
+ end
22
+
23
+ end
24
+
25
+ describe ".load_dir" do
26
+
27
+ it "loads" do
28
+ dirpath=TESTPATH + 'test_*.xml'
29
+ expect="abcdef"
30
+ actual=''
31
+ XML.load_dir(dirpath){|doc| doc.elements.each('foo/bar'){|e| actual+=e.attributes['x']}}
32
+ actual.must_equal expect
33
+ end
34
+
35
+ end
36
+
37
+ describe ".load_elements" do
38
+
39
+ it "loads" do
40
+ dirpath=TESTPATH + 'test_*.xml'
41
+ expect="<bar x='a'/><bar x='b'/><bar x='c'/><bar x='d'/><bar x='e'/><bar x='f'/>"
42
+ actual=''
43
+ XML.load_elements(dirpath,'foo/bar'){|elem| actual+=elem.to_s }
44
+ actual.must_equal expect
45
+ end
46
+
47
+ end
48
+
49
+ describe ".load_attributes" do
50
+
51
+ it "loads" do
52
+ dirpath=TESTPATH + 'test_*.xml'
53
+ expect=[["x", "a"], ["x", "b"], ["x", "c"], ["x", "d"], ["x", "e"], ["x", "f"]]
54
+ actual=[]
55
+ XML.load_attributes(dirpath,'foo/bar'){|attributes|
56
+ attributes.each{|attribute|
57
+ actual << [attribute[0], attribute[1]]
58
+ }
59
+ }
60
+ actual.must_equal expect
61
+ end
62
+
63
+ end
64
+
65
+ describe ".load_attributes_hash" do
66
+
67
+ it "loads" do
68
+ dirpath=TESTPATH + 'test_*.xml'
69
+ expect=[{"x"=>"a"}, {"x"=>"b"}, {"x"=>"c"}, {"x"=>"d"}, {"x"=>"e"}, {"x"=>"f"}]
70
+ actual=[]
71
+ XML.load_attributes_hash(dirpath,'foo/bar'){|attributes_hash|
72
+ actual << attributes_hash
73
+ }
74
+ assert_equal(expect,actual,'XML.load_attributes_hash')
75
+ actual.must_equal expect
76
+ end
77
+
78
+ end
79
+
80
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ Zw#�e��J���
2
+ MH ��#c)4���$��4S{x���b� �{Rf[Ƙz�oV:jfy���Å�h�%���
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_xml_load
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
14
+ Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
15
+ TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
16
+ WURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVE4d0RRWURWUVFLRXdaVGFY
17
+ aEJjbTB4RXpBUkJnTlZCQU1UQ25OcGVHRnliUzVqYjIwd0hoY05NVEF4Ck1q
18
+ RXpNak15TnpFeldoY05NVE13T1RBNE1qTXlOekV6V2pCZ01Rc3dDUVlEVlFR
19
+ R0V3SlZVekVUTUJFR0ExVUUKQ0JNS1EyRnNhV1p2Y201cFlURVdNQlFHQTFV
20
+ RUJ4TU5VMkZ1SUVaeVlXNWphWE5qYnpFUE1BMEdBMVVFQ2hNRwpVMmw0UVhK
21
+ dE1STXdFUVlEVlFRREV3cHphWGhoY20wdVkyOXRNSUdmTUEwR0NTcUdTSWIz
22
+ RFFFQkFRVUFBNEdOCkFEQ0JpUUtCZ1FDOTRtRDlKRHdCc3Vuc09JMFZSM0NY
23
+ WGJPV2c5Y1dhV2Npd0Z5Sk5GaU03QTlJOEtQTGZYVXcKUUM0Y3pVZTVadUc0
24
+ V0h2aW5yV2hrckNLKzFkV0Jxb0VDbHhkRi9Gb0tPNWErdG9uR0Nqam1meTgx
25
+ Sm1Gamp5eAplVHNqc0h5dncrUWlrOWtwZjlhajYrcG5rTnJWc3dnTkhWZWEy
26
+ bzl5YWJiRWlTNlZTZUpXb1FJREFRQUJvNEhGCk1JSENNQjBHQTFVZERnUVdC
27
+ QlF6UEp0cW1TZ2M1M2VETjdhU3pEUXdyOVRBTERDQmtnWURWUjBqQklHS01J
28
+ R0gKZ0JRelBKdHFtU2djNTNlRE43YVN6RFF3cjlUQUxLRmtwR0l3WURFTE1B
29
+ a0dBMVVFQmhNQ1ZWTXhFekFSQmdOVgpCQWdUQ2tOaGJHbG1iM0p1YVdFeEZq
30
+ QVVCZ05WQkFjVERWTmhiaUJHY21GdVkybHpZMjh4RHpBTkJnTlZCQW9UCkJs
31
+ TnBlRUZ5YlRFVE1CRUdBMVVFQXhNS2MybDRZWEp0TG1OdmJZSUpBS1B3RUVU
32
+ VTViSG9NQXdHQTFVZEV3UUYKTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFB
33
+ RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
34
+ d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
35
+ L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
36
+ dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-03-16 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: sixarm_ruby_rexml
42
+ requirement: &15166680 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: *15166680
51
+ description:
52
+ email: sixarm@sixarm.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - .gemtest
58
+ - Rakefile
59
+ - README.md
60
+ - VERSION
61
+ - lib/sixarm_ruby_xml_load.rb
62
+ - test/sixarm_ruby_xml_load_test.rb
63
+ - test/sixarm_ruby_xml_load_test/test_1.xml
64
+ - test/sixarm_ruby_xml_load_test/test_2.xml
65
+ homepage: http://sixarm.com/
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.11
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: SixArm.com » Ruby » XML#load methods
89
+ test_files:
90
+ - test/sixarm_ruby_xml_load_test.rb
91
+ - test/sixarm_ruby_xml_load_test/test_1.xml
92
+ - test/sixarm_ruby_xml_load_test/test_2.xml
93
+ has_rdoc: true
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ x�W���7� ���.��?2�Zߴ�‚�s6e��z�R��W@�� 1N����3l�*����ӼE�⮕t�y�����"b9�<�po� ��9��������^�b��5K>l~���