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.



402
403
404
405
406
407
408
409
410
411
# File 'lib/ruote/svc/participant_list.rb', line 402

def initialize(a)

  @regex = a.first

  @classname, @options = if a.last.is_a?(Array)
    [ a.last.first, a.last.last ]
  else
    [ a.last, nil ]
  end
end

Instance Attribute Details

#classnameObject

Returns the value of attribute classname.



400
401
402
# File 'lib/ruote/svc/participant_list.rb', line 400

def classname
  @classname
end

#optionsObject

Returns the value of attribute options.



400
401
402
# File 'lib/ruote/svc/participant_list.rb', line 400

def options
  @options
end

#regexObject

Returns the value of attribute regex.



400
401
402
# File 'lib/ruote/svc/participant_list.rb', line 400

def regex
  @regex
end

Class Method Details

.read(elt) ⇒ Object

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

[ regex, [ klass, opts ] ]


427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/ruote/svc/participant_list.rb', line 427

def self.read(elt)

  case elt

    when ParticipantEntry

      elt.to_a

    when 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
        elt.delete(name)
        options.delete(name)
      end
      name = name || elt['name']
      name = Ruote.regex_or_s(name)

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

      klass = (elt['classname'] || elt['class']).to_s

      [ regex, [ klass, options ] ]

    when Array

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

    else

      raise ArgumentError.new(
        "cannot read participant out of #{elt.inspect} (#{elt.class})")
  end
end

Instance Method Details

#to_aObject



413
414
415
416
# File 'lib/ruote/svc/participant_list.rb', line 413

def to_a

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

#to_sObject



418
419
420
421
# File 'lib/ruote/svc/participant_list.rb', line 418

def to_s

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