xml_parser 0.2.0 → 0.2.1
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 +4 -4
- data/README.md +1 -1
- data/lib/xml_parser/document.rb +13 -0
- data/lib/xml_parser/text.rb +21 -7
- data/lib/xml_parser/version.rb +1 -1
- data/xml_parser.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d6516f5dde191fe52f58147ee8a8333faea0abd
|
4
|
+
data.tar.gz: e529124eecaeccb34f653cdab202889f61ac5572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e05aae54a7607a93820e1895feac7d176b5214c32984e7f9c1a3977ead5fc54ee319b964b38c912967f15f90b8038a58bc91262a68f6ff28e9f374c95bdcb2b7
|
7
|
+
data.tar.gz: bf827d10eb6b6fa9dd89309c89b6ff4f63d800330db63b313adf3cfe2b3b2adfc116efc14055bcd08ac0f1799a4c37a55b98527aceb4e654a47da0fe07e29ff9
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/xml_parser`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
4
|
|
5
5
|
Parse Xml Document and String.
|
6
|
-
|
6
|
+
From String, and File.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
data/lib/xml_parser/document.rb
CHANGED
@@ -10,6 +10,7 @@ module XmlParser
|
|
10
10
|
# constructor.
|
11
11
|
# @param [String] xml_str xml string.
|
12
12
|
def initialize(xml_str)
|
13
|
+
|
13
14
|
@doc = REXML::Document.new(xml_str)
|
14
15
|
end
|
15
16
|
|
@@ -42,6 +43,18 @@ module XmlParser
|
|
42
43
|
}
|
43
44
|
end
|
44
45
|
|
46
|
+
# xml decl info.
|
47
|
+
# @return [REXML::XMLDecl] xml decl
|
48
|
+
def decl
|
49
|
+
@doc.xml_decl
|
50
|
+
end
|
51
|
+
|
52
|
+
# get document.
|
53
|
+
# @return [REXML::Document] document
|
54
|
+
def document
|
55
|
+
@doc
|
56
|
+
end
|
57
|
+
|
45
58
|
# initialize from File.
|
46
59
|
# @param [String] filepath read fileptah. absolute.
|
47
60
|
# @return [XmlParser::Document] parser.
|
data/lib/xml_parser/text.rb
CHANGED
@@ -8,31 +8,37 @@ module XmlParser
|
|
8
8
|
|
9
9
|
# normalize string.
|
10
10
|
# @param [String] str target string.
|
11
|
-
# @param [REXML
|
11
|
+
# @param [REXML::DocType] doctype document type.
|
12
12
|
# @param [Array] filter entity filter.
|
13
13
|
# @return [String] normalize string.
|
14
14
|
def self.normalize(str, doctype=nil, filter=nil)
|
15
15
|
|
16
|
-
# normalize.
|
17
16
|
REXML::Text.normalize(str, doctype, filter)
|
18
17
|
end
|
19
18
|
|
20
19
|
# normalize string array.
|
21
20
|
# @param [Array] strs target string array.
|
22
|
-
# @param [REXML
|
21
|
+
# @param [REXML::DocType] doctype document type.
|
23
22
|
# @param [Array] filter entity filter.
|
24
23
|
# @return [Array] normalize string array.
|
25
24
|
def self.multi_normalize(strs, doctype=nil, filter=nil)
|
26
25
|
|
27
26
|
# multi string normalize.
|
28
27
|
strs.map { |str|
|
29
|
-
normalize(str, doctype, filter)
|
28
|
+
value = normalize(str, doctype, filter)
|
29
|
+
|
30
|
+
# if block_given?, do block process.
|
31
|
+
if block_given?
|
32
|
+
yield value
|
33
|
+
else
|
34
|
+
value
|
35
|
+
end
|
30
36
|
}
|
31
37
|
end
|
32
38
|
|
33
39
|
# unnormalize string.
|
34
40
|
# @param [String] str target string.
|
35
|
-
# @param [REXML
|
41
|
+
# @param [REXML::DocType] doctype document type.
|
36
42
|
# @param [Array] filter entity filter.
|
37
43
|
# @return [String] unnormalize string.
|
38
44
|
def self.unnormalize(str, doctype=nil, filter=nil)
|
@@ -42,13 +48,21 @@ module XmlParser
|
|
42
48
|
|
43
49
|
# unnormalize string array.
|
44
50
|
# @param [Array] strs target string array.
|
45
|
-
# @param [REXML
|
51
|
+
# @param [REXML::DocType] doctype document type.
|
46
52
|
# @param [Array] filter entity filter.
|
47
53
|
# @return [Array] unnormalize string array.
|
48
54
|
def self.multi_unnormalize(strs, doctype=nil, filter=nil)
|
49
55
|
|
56
|
+
# multi string unnormalize.
|
50
57
|
strs.map { |str|
|
51
|
-
unnormalize(str, doctype, filter)
|
58
|
+
value = unnormalize(str, doctype, filter)
|
59
|
+
|
60
|
+
# if block_given?, do block process.
|
61
|
+
if block_given?
|
62
|
+
yield value
|
63
|
+
else
|
64
|
+
value
|
65
|
+
end
|
52
66
|
}
|
53
67
|
end
|
54
68
|
end
|
data/lib/xml_parser/version.rb
CHANGED
data/xml_parser.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["corporation.ore@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Parse Xml Document and String.}
|
13
|
-
spec.description = %q{Parse Xml Document and String.
|
13
|
+
spec.description = %q{Parse Xml Document and String.From String, and File.}
|
14
14
|
spec.homepage = "https://github.com/h-shigemoto/xml_parser"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xml_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- h.shigemoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description: Parse Xml Document and String.
|
55
|
+
description: Parse Xml Document and String.From String, and File.
|
56
56
|
email:
|
57
57
|
- corporation.ore@gmail.com
|
58
58
|
executables: []
|