Class: XAIML::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/xaiml/document.rb

Direct Known Subclasses

Element::Base

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

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_objectObject (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

#documentObject

Returns the value of attribute document.



3
4
5
# File 'lib/xaiml/document.rb', line 3

def document
  @document
end

#elementObject

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

Returns:

  • (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

#writeObject



59
60
61
# File 'lib/xaiml/document.rb', line 59

def write
  Ox.dump(@document)
end