Class: YAXML::Yaxml
- Inherits:
-
REXML::Document
- Object
- REXML::Document
- YAXML::Yaxml
- Defined in:
- lib/yaxml.rb
Instance Method Summary collapse
-
#initialize(source, options = {}) ⇒ Yaxml
constructor
- Constructor source
-
It can be a String or a file name.
-
#to_json ⇒ Object
The output is a JSON representation of YAXML object.
-
#to_yaml ⇒ Object
The output is a YAML representation of YAXML object.
-
#to_yaxml ⇒ Object
The output is a YAXML representation of YAXML object.
Constructor Details
#initialize(source, options = {}) ⇒ Yaxml
Constructor
- source
-
It can be a String or a file name.
- options
-
It is possible to pass the next options:
-
:root_name
It is the name of the root tag in the YAXML document. Defaults toDEFAULT_ROOT_NAME
-
:from_yaxml
If true, the source will be considered as YAXML input. If false, the source will be considered as YAML input. Defaults to :false
Example of use:
xml = Yaxml.new 'file.yml'
xml.write( $stdout, 2)
xml.to_json
xml.to_yaml
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/yaxml.rb', line 65 def initialize( source, ={} ) super() if [:from_yaxml] content = extract_content source doc = REXML::Document.new content self.add_element( doc.elements[1] ) if doc.elements[1] else #default is from_yaml [:root_name] ||= DEFAULT_ROOT_NAME doc = YAXML::yaml2yaxml( source, ) self.add_element( doc.elements[1] ) if doc.elements[1] end end |
Instance Method Details
#to_json ⇒ Object
The output is a JSON representation of YAXML object.
88 89 90 |
# File 'lib/yaxml.rb', line 88 def to_json YAXML::yaxml2json self end |
#to_yaml ⇒ Object
The output is a YAML representation of YAXML object.
83 84 85 |
# File 'lib/yaxml.rb', line 83 def to_yaml YAXML::yaxml2yaml self end |
#to_yaxml ⇒ Object
The output is a YAXML representation of YAXML object.
93 94 95 |
# File 'lib/yaxml.rb', line 93 def to_yaxml self.to_s end |