demolisher 0.3.3 → 0.4.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.
- data/README.rdoc +10 -0
- data/VERSION +1 -1
- data/demolisher.gemspec +7 -3
- data/lib/demolisher.rb +12 -1
- data/test/demolisher_test.rb +13 -0
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
Works in a similar fashion to Builder but is instead used for extracting information from XML files rather than building them.
|
4
4
|
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
You can install using any of the following methods
|
8
|
+
|
9
|
+
$ gem install demolisher
|
10
|
+
$ gem install demolisher -s http://gemcutter.org
|
11
|
+
$ gem install geoffgarside-demolisher -s http://gems.github.com
|
12
|
+
|
13
|
+
the first two should always be stable, the latter github one should be stable but there are no guarantees.
|
14
|
+
|
5
15
|
== Example
|
6
16
|
|
7
17
|
Given the simple XML example file below
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/demolisher.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{demolisher}
|
5
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Geoff Garside"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-31}
|
10
13
|
s.email = %q{geoff@geoffgarside.co.uk}
|
11
14
|
s.extra_rdoc_files = [
|
12
15
|
"LICENSE",
|
@@ -29,7 +32,7 @@ Gem::Specification.new do |s|
|
|
29
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
30
33
|
s.require_paths = ["lib"]
|
31
34
|
s.rubyforge_project = %q{demolisher}
|
32
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
33
36
|
s.summary = %q{Gem for extracting information from XML files, think Builder but backwards}
|
34
37
|
s.test_files = [
|
35
38
|
"test/demolisher_test.rb",
|
@@ -49,3 +52,4 @@ Gem::Specification.new do |s|
|
|
49
52
|
s.add_dependency(%q<libxml-ruby>, [">= 1.1.3"])
|
50
53
|
end
|
51
54
|
end
|
55
|
+
|
data/lib/demolisher.rb
CHANGED
@@ -3,13 +3,24 @@ require 'xml'
|
|
3
3
|
module Demolisher
|
4
4
|
# Demolish an XML file or XML::Parser object.
|
5
5
|
def self.demolish(file_or_xml_parser)
|
6
|
-
file_or_xml_parser =
|
6
|
+
file_or_xml_parser = new_parser(file_or_xml_parser) if file_or_xml_parser.kind_of?(String)
|
7
7
|
node = Node.new(file_or_xml_parser.parse, true)
|
8
8
|
|
9
9
|
yield node if block_given?
|
10
10
|
node
|
11
11
|
end
|
12
12
|
|
13
|
+
# ---
|
14
|
+
# Creates an XML::Parser from the string if its a string or the file if its a file path
|
15
|
+
# +++
|
16
|
+
def self.new_parser(string_or_filepath)
|
17
|
+
if File.exist?(string_or_filepath)
|
18
|
+
XML::Parser.file(string_or_filepath)
|
19
|
+
else
|
20
|
+
XML::Parser.string(string_or_filepath)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
13
24
|
# Handles all the complexity of accessing the XML contents
|
14
25
|
class Node
|
15
26
|
# Creates a new Node object.
|
data/test/demolisher_test.rb
CHANGED
@@ -48,4 +48,17 @@ class DemolisherTest < Test::Unit::TestCase
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
+
context "Demolished XML String" do
|
52
|
+
setup do
|
53
|
+
@xml =<<-EOXML
|
54
|
+
<hi>
|
55
|
+
<there>Geoff</there>
|
56
|
+
</hi>
|
57
|
+
EOXML
|
58
|
+
@demolisher = Demolisher.demolish(@xml)
|
59
|
+
end
|
60
|
+
should "find Geoff" do
|
61
|
+
assert_equal 'Geoff', @demolisher.hi.there
|
62
|
+
end
|
63
|
+
end
|
51
64
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: demolisher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geoff Garside
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-31 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,8 +43,10 @@ files:
|
|
43
43
|
- test/demolisher_test.rb
|
44
44
|
- test/test.xml
|
45
45
|
- test/test_helper.rb
|
46
|
-
has_rdoc:
|
46
|
+
has_rdoc: true
|
47
47
|
homepage: http://github.com/geoffgarside/demolisher
|
48
|
+
licenses: []
|
49
|
+
|
48
50
|
post_install_message:
|
49
51
|
rdoc_options:
|
50
52
|
- --charset=UTF-8
|
@@ -65,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
67
|
requirements: []
|
66
68
|
|
67
69
|
rubyforge_project: demolisher
|
68
|
-
rubygems_version: 1.3.
|
70
|
+
rubygems_version: 1.3.5
|
69
71
|
signing_key:
|
70
72
|
specification_version: 3
|
71
73
|
summary: Gem for extracting information from XML files, think Builder but backwards
|