Class: XAIML::Document
- Inherits:
-
Object
- Object
- XAIML::Document
- Defined in:
- lib/xaiml/document.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.allowed_object ⇒ Object
readonly
Returns the value of attribute allowed_object.
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.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/xaiml/document.rb', line 12 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 |
Class Attribute Details
.allowed_object ⇒ Object (readonly)
Returns the value of attribute allowed_object.
7 8 9 |
# File 'lib/xaiml/document.rb', line 7 def allowed_object @allowed_object end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
3 4 5 |
# File 'lib/xaiml/document.rb', line 3 def document @document end |
#element ⇒ Object
Returns the value of attribute element.
4 5 6 |
# File 'lib/xaiml/document.rb', line 4 def element @element end |
Class Method Details
.load_file(file) ⇒ Object
80 81 82 83 84 |
# File 'lib/xaiml/document.rb', line 80 def load_file(file) instance = new instance.document = Ox.load_file(file) instance end |
Instance Method Details
#allowed_object?(object) ⇒ Boolean
49 50 51 52 53 54 55 56 57 |
# File 'lib/xaiml/document.rb', line 49 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
25 26 27 28 29 30 31 32 33 |
# File 'lib/xaiml/document.rb', line 25 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
35 36 37 |
# File 'lib/xaiml/document.rb', line 35 def append_into(target, object) @element.send(target.to_s) << object.element end |
#prepend_child(object) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/xaiml/document.rb', line 39 def prepend_child(object) if object.is_a?(Array) object.each do |e| unshift(e) end else unshift(object) end end |
#write ⇒ Object
59 60 61 |
# File 'lib/xaiml/document.rb', line 59 def write Ox.dump(@document) end |