xml_parser 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bff8dc1fc6aef722fde275bb33821af85f364be
4
- data.tar.gz: 94367da076ea09440a81d80b9806b6da29da01b9
3
+ metadata.gz: cc02cb0aed38ab5e931fa76958e3d4cfb43266e1
4
+ data.tar.gz: b875268acaa289c6fea37828d79d3432faecb9dc
5
5
  SHA512:
6
- metadata.gz: 13569866bdb09f714dce4bdc8852cc5ffdb0a2166092e741d789ff0bd9654ba3d4f8a408d97cd0f294d4650d1c6ed3a442ea47e540a24c99f804582e30b6a290
7
- data.tar.gz: 400e0fe0cf0b7637db3ec822d6409249ae75604a549733b65463e698965d232638863326a251ab579ae88d4e9fc63fab7462bcc6b75eac4bb00be44c68a60652
6
+ metadata.gz: 1897c41ffa71821789c9b34cb0dbcb5be8b5de7984e920c3ad4b146171e1116de16dd8b814bd76a284a3875315c0ea80de4d735d1c4f5b642dcb87f1eefd4a7b
7
+ data.tar.gz: 48d633a09b99c1196f5492f0503db54c3c0359c7160071efacc232587e9d52ecb2e976e9798a293780df5e9f65353f131c4f708dd76f172cfd66f08e486d5d85
data/README.md CHANGED
@@ -34,13 +34,16 @@ str = XmlParser::Text.multi_unnormalize(["a > b; < c", "a > b; < c"]
34
34
  # read xml
35
35
  doc = XmlParser::Document.new("<sample><elm>sample xml</elm></sample>")
36
36
  # you can read from file.
37
- # doc = XmlParser::Document.from_file("/var/sample.xml")
37
+ doc = XmlParser::Document.from_file("/var/sample.xml")
38
38
  match_values = doc.xpath_map("/sample/test/@name") { |elm|
39
39
  puts elm
40
40
  }
41
41
 
42
42
  # parse xml from yaml file
43
43
  doc = XmlParser::Document.from_yml("/var/home/hoge.yml", "root_element_name", "default_attr_name")
44
+
45
+ # parse xml from hash
46
+ doc = XmlParser::Document.from_hash({a: "v1", b: "v2"}, "root_element_name", "default_attr_name")
44
47
  ```
45
48
 
46
49
  ## Development
@@ -78,7 +78,7 @@ module XmlParser
78
78
  # @param [String] filepath read yml filepath. absolute.
79
79
  # @param [String] root_name root element name
80
80
  # @param [String] attr_name attribute name
81
- # @return [XmlParser::Document] parser.
81
+ # @return [XmlParser::Document] parser
82
82
  def self.from_yml(filepath, root_name="root", attr_name="value")
83
83
 
84
84
  # load yml file.
@@ -87,13 +87,23 @@ module XmlParser
87
87
  parse_xml_from_hash(yml, root_name, attr_name)
88
88
  end
89
89
 
90
+ # initialize from hash
91
+ # @param [Hash] hash hash
92
+ # @param [String] root_name root element name
93
+ # @param [String] attr_name attribute name
94
+ # @return [XmlParser::Document] parser
95
+ def self.from_hash(hash, root_name="root", attr_name="value")
96
+
97
+ parse_xml_from_hash(hash, root_name, attr_name)
98
+ end
99
+
90
100
  private
91
101
 
92
102
  # parse hash to xml.
93
103
  # @param [Hash] hash hash
94
104
  # @param [String] root_name root element name
95
105
  # @param [String] attr_name attribute name
96
- # @return [XmlParser::Document] document
106
+ # @return [XmlParser::Document] parser
97
107
  def self.parse_xml_from_hash(hash, root_name, attr_name)
98
108
 
99
109
  doc = REXML::Document.new("<#{root_name}/>")
@@ -118,7 +128,7 @@ module XmlParser
118
128
 
119
129
  # if value is String
120
130
  if value.is_a?(String)
121
- # set element. default attribute name = value.
131
+ # set attribute. default attribute name = value.
122
132
  elm.add_attribute(attr_name, value)
123
133
  # if value is Hash
124
134
  elsif value.is_a?(Hash)
@@ -132,4 +142,4 @@ module XmlParser
132
142
  elm
133
143
  end
134
144
  end
135
- end
145
+ end
@@ -1,3 +1,3 @@
1
1
  module XmlParser
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
4
+ version: 0.3.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-26 00:00:00.000000000 Z
11
+ date: 2016-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,9 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.6.3
97
+ rubygems_version: 2.6.6
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: Parse Xml Document and String.
101
101
  test_files: []
102
- has_rdoc: