Class: Ruote::ParticipantEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/ruote/svc/participant_list.rb

Overview

A helper class, for ParticipantList#list, which returns a list (order matters) of ParticipantEntry instances.

See Engine#participant_list

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a) ⇒ ParticipantEntry

Returns a new instance of ParticipantEntry.



334
335
336
337
338
339
340
341
342
343
# File 'lib/ruote/svc/participant_list.rb', line 334

def initialize(a)
  @regex = a.first
  if a.last.is_a?(Array)
    @classname = a.last.first
    @options = a.last.last
  else
    @classname = a.last
    @options = nil
  end
end

Instance Attribute Details

#classnameObject

Returns the value of attribute classname.



332
333
334
# File 'lib/ruote/svc/participant_list.rb', line 332

def classname
  @classname
end

#optionsObject

Returns the value of attribute options.



332
333
334
# File 'lib/ruote/svc/participant_list.rb', line 332

def options
  @options
end

#regexObject

Returns the value of attribute regex.



332
333
334
# File 'lib/ruote/svc/participant_list.rb', line 332

def regex
  @regex
end

Class Method Details

.read(elt) ⇒ Object

Makes sense of whatever is given to it, returns something like

[ regex, [ klass, opts ] ]


359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# File 'lib/ruote/svc/participant_list.rb', line 359

def self.read(elt)

  return elt.to_a if elt.is_a?(ParticipantEntry)

  if elt.is_a?(Hash)

    options = elt['options'] || elt.reject { |k, v|
      %w[ name regex regexp class classname ].include?(k)
    }

    name = elt.find { |k, v| v == nil }
    if name
      name = name.first
      elt.delete(name)
      options.delete(name)
    end
    name = name || elt['name']
    name = Ruote.regex_or_s(name)

    regex = name
    unless name
      regex = Ruote.regex_or_s(elt['regex'] || elt['regexp'])
      regex = regex.is_a?(String) ? Regexp.new(regex) : regex
    end

    klass = elt['classname'] || elt['class']

    return [ regex, [ klass, options ] ]
  end

  # else elt is a Array

  return [ Ruote.regex_or_s(elt[0]), [ elt[1], elt[2] ] ] if elt.size == 3

  [ Ruote.regex_or_s(elt[0]), elt[1] ]
end

Instance Method Details

#to_aObject



345
346
347
348
# File 'lib/ruote/svc/participant_list.rb', line 345

def to_a

  [ @regex, [ @classname, @options ] ]
end

#to_sObject



350
351
352
353
# File 'lib/ruote/svc/participant_list.rb', line 350

def to_s

  "/#{@regex}/ ==> #{@classname} #{@options.inspect}"
end