Method: Xbd.parse
- Defined in:
- lib/xbd/xbd.rb
.parse(source) ⇒ Object
XBD.parse accepts:
a string or
any object that returns a string in response to the method "read"
(for example, an open file handle)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/xbd/xbd.rb', line 98 def Xbd.parse(source) #treat source as a stream(file) if it isn't a string source=source.read.force_encoding("BINARY") if source.class!=String # read the header raise "Not a valid XBD file" unless source[0..SBDXML_HEADER.length-1]==SBDXML_HEADER index=SBDXML_HEADER.length # read each of the 3 dictionaries in order ,index=Dictionary.parse(source,index) attrsd,index=Dictionary.parse(source,index) valuesd,index=Dictionary.parse(source,index) # read all tags, return the root-tag Tag.parse(source,index,,attrsd,valuesd)[0] end |