Module: Xbd

Defined in:
lib/xbd/xbd.rb,
lib/xbd/asi.rb,
lib/xbd/version.rb,
lib/xbd/xbd_tag.rb,
lib/xbd/xbd_dictionary.rb

Overview

********************************* Xbd Module *********************************

Defined Under Namespace

Classes: Asi, Dictionary, Tag

Constant Summary collapse

SBDXML_HEADER =
"SBDXML\1\0"
XML_ESCAPE_CODES =

********************************************************** XML escaping ********************************************************** Used when converting TO xml (Xbd::Tag.to_s) Note, some of these codes are actually invalid strict XML because XML has no escape codes for some values.

SBD: WTF! (I'm still surprised by this, but it appears to be true.)
{
  "�"=>0,
  ""=>1,
  ""=>2,
  ""=>3,
  ""=>4,
  ""=>5,
  ""=>6,
  ""=>7,
  ""=>8,
  "	"=>9,
  "
"=>10,
  ""=>11,
  ""=>12,
  "
"=>13,
  ""=>14,
  ""=>15,
  ""=>16,
  ""=>17,
  ""=>18,
  ""=>19,
  ""=>20,
  ""=>21,
  ""=>22,
  ""=>23,
  ""=>24,
  ""=>25,
  ""=>26,
  ""=>27,
  ""=>28,
  ""=>29,
  ""=>30,
  ""=>31,
  """=>34,   #"
  "&"=>38,    #&
  "'"=>39,   #'
  "&lt;"=>60,     #<
  "&gt;"=>62      #>
}
VERSION =
"0.1.1"
@@escape_for_xml =
[]

Class Method Summary collapse

Class Method Details

.load_from_file(filename) ⇒ Object

Load XBD from filename



116
117
118
# File 'lib/xbd/xbd.rb', line 116

def Xbd.load_from_file(filename)
  Xbd.parse(File.open(filename,"rb"))
end

.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
  tagsd,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,tagsd,attrsd,valuesd)[0]
end

.xml_escape(s) ⇒ Object



88
89
90
91
92
# File 'lib/xbd/xbd.rb', line 88

def self.xml_escape(s)
  out=""
  s.each_byte {|b| out<< @@escape_for_xml[b]}
  out
end