Class: Edoors::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/edoors/link.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, dsts, keys = nil, value = nil) ⇒ Link

creates a Link object from the arguments.

Parameters:

  • link source name

  • destinations to apply to the particle on linking success

  • (defaults to: nil)

    keys to apply as link_keys to the particle on linking success

  • (defaults to: nil)

    will be used to check linking with particles

See Also:



41
42
43
44
45
46
47
# File 'lib/edoors/link.rb', line 41

def initialize src, dsts, keys=nil, value=nil
    @src = src
    @dsts = dsts
    @keys = keys
    @value = value
    @door = nil         # pointer to the source set from @src by Room#add_link
end

Instance Attribute Details

#doorObject

Returns the value of attribute door.



83
84
85
# File 'lib/edoors/link.rb', line 83

def door
  @door
end

#dstsObject (readonly)

Returns the value of attribute dsts.



84
85
86
# File 'lib/edoors/link.rb', line 84

def dsts
  @dsts
end

#keysObject (readonly)

Returns the value of attribute keys.



84
85
86
# File 'lib/edoors/link.rb', line 84

def keys
  @keys
end

#srcObject (readonly)

Returns the value of attribute src.



84
85
86
# File 'lib/edoors/link.rb', line 84

def src
  @src
end

#valueObject (readonly)

Returns the value of attribute value.



84
85
86
# File 'lib/edoors/link.rb', line 84

def value
  @value
end

Class Method Details

.from_particle(p) ⇒ Object

creates a Link object from the data of a particle

Parameters:

  • the Particle to get Link attributes from



78
79
80
81
# File 'lib/edoors/link.rb', line 78

def self.from_particle p
    pl = p.payload
    Edoors::Link.new pl[Edoors::LNK_SRC], pl[Edoors::LNK_DSTS], pl[Edoors::LNK_KEYS], pl[Edoors::LNK_VALUE]
end

.json_create(o) ⇒ Object

creates a Link object from a JSON data

Parameters:

  • belongs to JSON parser

Raises:

  • Edoors::Exception if the json kls attribute is wrong



69
70
71
72
# File 'lib/edoors/link.rb', line 69

def self.json_create o
    raise Edoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name
    self.new o['src'], o['dsts'], o['keys'], o['value']
end

Instance Method Details

#to_json(*a) ⇒ Object

called by JSON#generate to serialize the Link object into JSON data

Parameters:

  • belongs to JSON generator



53
54
55
56
57
58
59
60
61
# File 'lib/edoors/link.rb', line 53

def to_json *a
    {
        'kls'       => self.class.name,
        'src'       => @src,
        'dsts'      => @dsts,
        'keys'      => @keys,
        'value'     => @value
    }.to_json *a
end