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.



399
400
401
402
403
404
405
406
407
408
# File 'lib/ruote/svc/participant_list.rb', line 399

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.



397
398
399
# File 'lib/ruote/svc/participant_list.rb', line 397

def classname
  @classname
end

#optionsObject

Returns the value of attribute options.



397
398
399
# File 'lib/ruote/svc/participant_list.rb', line 397

def options
  @options
end

#regexObject

Returns the value of attribute regex.



397
398
399
# File 'lib/ruote/svc/participant_list.rb', line 397

def regex
  @regex
end

Class Method Details

.read(elt) ⇒ Object

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

[ regex, [ klass, opts ] ]


424
425
426
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
# File 'lib/ruote/svc/participant_list.rb', line 424

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



410
411
412
413
# File 'lib/ruote/svc/participant_list.rb', line 410

def to_a

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

#to_sObject



415
416
417
418
# File 'lib/ruote/svc/participant_list.rb', line 415

def to_s

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