Class: ArcWeld::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/arc_weld/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Reference

Returns a new instance of Reference.



5
6
7
8
# File 'lib/arc_weld/reference.rb', line 5

def initialize(*args)
  Hash[*args].each {|k,v| self.send(format('%s=',k),v)}
  @type ||= 'Group'
end

Instance Attribute Details

#externalIDObject

Returns the value of attribute externalID.



3
4
5
# File 'lib/arc_weld/reference.rb', line 3

def externalID
  @externalID
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/arc_weld/reference.rb', line 3

def id
  @id
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/arc_weld/reference.rb', line 3

def type
  @type
end

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/arc_weld/reference.rb', line 3

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
17
18
# File 'lib/arc_weld/reference.rb', line 14

def ==(other)
  [:type, :uri, :id, :externalID].all? do |attr|
    self.send(attr) == other.send(attr)
  end
end

#identityObject



28
29
30
31
32
33
34
35
36
# File 'lib/arc_weld/reference.rb', line 28

def identity
  if id!=nil
    {:id => id}
  elsif externalID!=nil
    {:externalID => externalID}
  else
    {}
  end
end

#identity_hashObject



20
21
22
23
24
25
26
# File 'lib/arc_weld/reference.rb', line 20

def identity_hash
  if identity=={}
    {}
  else
    Hash[identity.keys.map {|k| format('@%s',k.to_s)}.zip(identity.values)]
  end
end

#refObject



10
11
12
# File 'lib/arc_weld/reference.rb', line 10

def ref
  self
end

#renderObject



47
48
49
# File 'lib/arc_weld/reference.rb', line 47

def render
  Gyoku.xml(to_h, key_converter: :none)
end

#to_hObject



38
39
40
41
42
43
44
45
# File 'lib/arc_weld/reference.rb', line 38

def to_h
 {
    'ref/' => {
      :@type => type,
      :@uri   => uri
    }.merge(identity_hash)
  }
end