Class: Kwaff::Rexml::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/kwaff/rexml.rb

Overview

Kwaff::Rexml::Translator

Direct Known Subclasses

KwaffTranslator, ReverseTranslator

Instance Method Summary collapse

Constructor Details

#initialize(toppings = {}) ⇒ Translator

Returns a new instance of Translator.



158
159
160
161
162
163
# File 'lib/kwaff/rexml.rb', line 158

def initialize(toppings={})
   @toppings = toppings
   @newline  = toppings[:newline] || "\n"
   @space    = ' ' * (toppings[:output_indent_width] || 2)
   @output   = ''
end

Instance Method Details

#translate(rexml_node, level = 0) ⇒ Object

don’t override!



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/kwaff/rexml.rb', line 166

def translate(rexml_node, level=0)
   ## cannot use visitor-pattern
   case rexml_node
   when REXML::Document
      return translate_document(rexml_node, level)
   when REXML::Element
      return translate_element(rexml_node, level)
   when REXML::Comment
      return translate_comment(rexml_node, level)
   when REXML::Text
      return translate_text(rexml_node, level)
   else
      errmsg = "translation error (rexml_node.class.name=#{rexml_node.class.name})."
      raise Kwaff::TranslationError.new(errmsg)
   end
end

#translate_comment(rexml_node, level = 0) ⇒ Object

abstract method



194
195
196
# File 'lib/kwaff/rexml.rb', line 194

def translate_comment(rexml_node, level=0)
   raise NotImplementedError.new("#{self.class.name}#translate_comment() is not implemented.")
end

#translate_document(rexml_node, level = 0) ⇒ Object

abstract method



184
185
186
# File 'lib/kwaff/rexml.rb', line 184

def translate_document(rexml_node, level=0)
   raise NotImplementedError.new("#{self.class.name}#translate_document() is not implemented.")
end

#translate_element(rexml_node, level = 0) ⇒ Object

abstract method



189
190
191
# File 'lib/kwaff/rexml.rb', line 189

def translate_element(rexml_node, level=0)
   raise NotImplementedError.new("#{self.class.name}#translate_element() is not implemented.")
end

#translate_text(rexml_node, level = 0) ⇒ Object

abstract method



199
200
201
# File 'lib/kwaff/rexml.rb', line 199

def translate_text(rexml_node, level=0)
   raise NotImplementedError.new("#{self.class.name}#translate_text() is not implemented.")
end