xml_parser 0.3.2 → 0.3.3
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 +4 -2
- data/lib/xml_parser/document.rb +14 -1
- data/lib/xml_parser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b96b2cc750d00075521029a293cfe21e34e0bb5
|
4
|
+
data.tar.gz: 952758a9f2ccc3c21b74baf96515c825bc2ecfc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86a3dac02129d5dc96466a128679d0b098d0ee151563f7e8aef5b28e1289cea54c0249a9022ab6dbe5d895b282b77a7d084bb99330b96eb43e8888b119e1b675
|
7
|
+
data.tar.gz: c33623fbd341dde8f6a24f60ea48b5c41073f10a6bd71167ed0463c55d467232d662e4378749d2c15caefa4e6a0e226a1dc5fb0be8df311511543b0beac080dc
|
data/README.md
CHANGED
@@ -39,8 +39,10 @@ match_values = doc.xpath_map("/sample/test/@name") { |elm|
|
|
39
39
|
puts elm
|
40
40
|
}
|
41
41
|
|
42
|
-
# parse xml from yaml file
|
43
|
-
|
42
|
+
# parse xml from yaml file.
|
43
|
+
# initialize from yaml string, use XmlParser::Document.from_yml method.
|
44
|
+
# only yaml of the hash form is dealing.
|
45
|
+
doc = XmlParser::Document.from_yml_file("/var/home/hoge.yml", "root_element_name", "default_attr_name")
|
44
46
|
|
45
47
|
# parse xml from hash
|
46
48
|
doc = XmlParser::Document.from_hash({a: "v1", b: "v2"}, "root_element_name", "default_attr_name")
|
data/lib/xml_parser/document.rb
CHANGED
@@ -91,12 +91,25 @@ module XmlParser
|
|
91
91
|
XmlParser::Document.new(xml_str)
|
92
92
|
end
|
93
93
|
|
94
|
+
# initialize from yml string.
|
95
|
+
# @param [String] yml_string yaml string.
|
96
|
+
# @param [String] root_name root element name
|
97
|
+
# @param [String] attr_name attribute name
|
98
|
+
# @return [XmlParser::Document] parser
|
99
|
+
def self.from_yml(yml_string, root_name="root", attr_name="value")
|
100
|
+
|
101
|
+
# load yml string.
|
102
|
+
yml = YAML.load(yml_string)
|
103
|
+
# parse to xml.
|
104
|
+
parse_xml_from_hash(yml, root_name, attr_name)
|
105
|
+
end
|
106
|
+
|
94
107
|
# initialize from yml file.
|
95
108
|
# @param [String] filepath read yml filepath. absolute.
|
96
109
|
# @param [String] root_name root element name
|
97
110
|
# @param [String] attr_name attribute name
|
98
111
|
# @return [XmlParser::Document] parser
|
99
|
-
def self.
|
112
|
+
def self.from_yml_file(filepath, root_name="root", attr_name="value")
|
100
113
|
|
101
114
|
# load yml file.
|
102
115
|
yml = YAML.load_file(filepath)
|
data/lib/xml_parser/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.3
|
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-
|
11
|
+
date: 2016-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|