Class: MelissaData::WebSmart::XMLParser
- Inherits:
-
Object
- Object
- MelissaData::WebSmart::XMLParser
- Defined in:
- lib/melissa_data/web_smart/xml.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#xml_document ⇒ Object
Returns the value of attribute xml_document.
Instance Method Summary collapse
- #children?(xml_node) ⇒ Boolean
-
#initialize(xml) ⇒ XMLParser
constructor
A new instance of XMLParser.
- #viperize(string) ⇒ Object
- #viperize_hash(hash) ⇒ Object
Constructor Details
#initialize(xml) ⇒ XMLParser
Returns a new instance of XMLParser.
6 7 8 |
# File 'lib/melissa_data/web_smart/xml.rb', line 6 def initialize(xml) @xml_document = xml end |
Instance Attribute Details
#xml_document ⇒ Object
Returns the value of attribute xml_document.
4 5 6 |
# File 'lib/melissa_data/web_smart/xml.rb', line 4 def xml_document @xml_document end |
Instance Method Details
#children?(xml_node) ⇒ Boolean
10 11 12 |
# File 'lib/melissa_data/web_smart/xml.rb', line 10 def children?(xml_node) xml_node.children.empty? end |
#viperize(string) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/melissa_data/web_smart/xml.rb', line 18 def viperize(string) word = string.to_s.dup word.gsub!(/::/, '/') word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2') word.gsub!(/([a-z\d])([A-Z])/,'\1_\2') word.tr!("-", "_") word.downcase! word.to_sym end |
#viperize_hash(hash) ⇒ Object
14 15 16 |
# File 'lib/melissa_data/web_smart/xml.rb', line 14 def viperize_hash hash hash.map { |key, value| { viperize(key.to_s) => value } }.reduce(:merge) end |