Class: KXML::Document
- Inherits:
-
Object
- Object
- KXML::Document
- Defined in:
- lib/xml/kxml.rb
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#root ⇒ Object
Returns the value of attribute root.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(data) {|@root| ... } ⇒ Document
constructor
A new instance of Document.
- #save_to(file_path) ⇒ Object
- #to_s(format = Format::PRETTY) ⇒ Object
Constructor Details
#initialize(data) {|@root| ... } ⇒ Document
Returns a new instance of Document.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/xml/kxml.rb', line 7 def initialize(data) case data when KXML::Node @root = data when String if data =~ /^[<>\/]/ parse_from_string(data) else @root = Node.new(data) end when File parse_from_file(data) else raise "Unsupport Param Type : #{data.class}" end yield @root if block_given? end |
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
3 4 5 |
# File 'lib/xml/kxml.rb', line 3 def encoding @encoding end |
#root ⇒ Object
Returns the value of attribute root.
5 6 7 |
# File 'lib/xml/kxml.rb', line 5 def root @root end |
#version ⇒ Object
Returns the value of attribute version.
4 5 6 |
# File 'lib/xml/kxml.rb', line 4 def version @version end |
Instance Method Details
#save_to(file_path) ⇒ Object
25 26 27 28 29 |
# File 'lib/xml/kxml.rb', line 25 def save_to(file_path) File.open(file_path,"w+"){|f| f.write to_s } end |