Class: XAIML::Document
- Inherits:
-
Object
- Object
- XAIML::Document
- Defined in:
- lib/xaiml/document.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#element ⇒ Object
Returns the value of attribute element.
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_object?(object) ⇒ Boolean
- #append_child(object) ⇒ Object
- #append_into(target, object) ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #prepend_child(object) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xaiml/document.rb', line 11 def initialize @document = Ox::Document.new(version: "1.0", encoding: "UTF-8") aiml = Ox::Element.new("aiml") aiml[:version] = "2.0.0" aiml[:xmlns] = "http://www.nttdocomo.com/aiml/schema" aiml[:'xmlns:html'] = "http://www.w3.org/1999/xhtml" aiml[:'xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance" aiml[:'xsi:schemaLocation'] = "http://www.nttdocomo.com/aiml/schema/AIML.xsd" @document << aiml @element = aiml end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
5 6 7 |
# File 'lib/xaiml/document.rb', line 5 def document @document end |
#element ⇒ Object
Returns the value of attribute element.
5 6 7 |
# File 'lib/xaiml/document.rb', line 5 def element @element end |
Class Method Details
.allowed_object ⇒ Object
7 8 9 |
# File 'lib/xaiml/document.rb', line 7 def self.allowed_object ["Element::Topic", "Element::Category"] end |
.load_file(file) ⇒ Object
83 84 85 86 87 |
# File 'lib/xaiml/document.rb', line 83 def load_file(file) instance = new instance.document = Ox.load_file(file) instance end |
Instance Method Details
#allowed_object?(object) ⇒ Boolean
48 49 50 51 52 53 54 55 56 |
# File 'lib/xaiml/document.rb', line 48 def allowed_object?(object) allowed_object = self.class.allowed_object return true if !allowed_object || (object.is_a?(String) && object.empty?) allowed_object.any? do |item| item = XAIML.const_get(item) if item.is_a?(String) object.is_a?(item) end end |
#append_child(object) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/xaiml/document.rb', line 24 def append_child(object) if object.is_a?(Array) object.each do |e| append(e) end else append(object) end end |
#append_into(target, object) ⇒ Object
34 35 36 |
# File 'lib/xaiml/document.rb', line 34 def append_into(target, object) @element.send(target.to_s) << object.element end |
#prepend_child(object) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/xaiml/document.rb', line 38 def prepend_child(object) if object.is_a?(Array) object.each do |e| unshift(e) end else unshift(object) end end |
#write ⇒ Object
58 59 60 |
# File 'lib/xaiml/document.rb', line 58 def write Ox.dump(@document) end |