Class: Sem4r::Operation

Inherits:
Object
  • Object
show all
Includes:
Sem4rSoap::SoapAttributes
Defined in:
lib/sem4r/operation.rb

Overview

Contains an operand. Operand can be everything that respond_to :to_xml and :xml

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Instance Attribute Details

#operation_typeObject (readonly)

Returns the value of attribute operation_type.



53
54
55
# File 'lib/sem4r/operation.rb', line 53

def operation_type
  @operation_type
end

Class Method Details

.add(operand) ⇒ Object



35
36
37
# File 'lib/sem4r/operation.rb', line 35

def add(operand)
  self.new.add(operand)
end

.remove(operand) ⇒ Object



39
40
41
# File 'lib/sem4r/operation.rb', line 39

def remove(operand)
  self.new.remove(operand)
end

.set(operand) ⇒ Object



43
44
45
# File 'lib/sem4r/operation.rb', line 43

def set(operand)
  self.new.set(operand)
end

Instance Method Details

#_xml(t) ⇒ Object

Raises:



74
75
76
77
78
# File 'lib/sem4r/operation.rb', line 74

def _xml(t)
  raise Sem4rError, "Missing Operand" unless @operand
  t.operator operator
  @operand.xml(t, "operand")
end

#add(operand) ⇒ Object



56
57
58
59
60
# File 'lib/sem4r/operation.rb', line 56

def add(operand)
  operator "ADD"
  @operand = operand
  self
end

#remove(operand) ⇒ Object



62
63
64
65
66
# File 'lib/sem4r/operation.rb', line 62

def remove(operand)
  operator "REMOVE"
  @operand = operand
  self
end

#set(operand) ⇒ Object



68
69
70
71
72
# File 'lib/sem4r/operation.rb', line 68

def set(operand)
  operator "SET"
  @operand = operand
  self
end

#to_xml(tag = "operations") ⇒ Object

Raises:



92
93
94
95
# File 'lib/sem4r/operation.rb', line 92

def to_xml(tag = "operations")
  raise Sem4rError, "Missing Operand" unless @operand
  xml(Builder::XmlMarkup.new, tag)
end

#xml(t, tag = nil) ⇒ Object

Raises:



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/sem4r/operation.rb', line 80

def xml(t, tag = nil)
  raise Sem4rError, "Missing Operand" unless @operand
  if tag
    attrs = {}
    attrs = {'xsi:type'=> operation_type} if operation_type
    attrs.merge! @attrs if @attrs
    t.__send__(tag, attrs) { |t| _xml(t) }
  else
    _xml(t)
  end
end