Class: SpecTools::Event

Inherits:
Object
  • Object
show all
Extended by:
SpecToolsExtensions
Defined in:
lib/spectools.rb,
lib/vnmsh.rb

Overview

SpecTools::Event

Represents a Spectrum event

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpecToolsExtensions

call_default_extension, call_extension, method_missing, method_missing

Constructor Details

#initialize(time = nil, type = nil, model = Model.new, message = '', landscape = Landscape.new) ⇒ Event

Returns a new instance of Event.



547
548
549
550
551
552
553
554
555
556
557
# File 'lib/spectools.rb', line 547

def initialize(time = nil, type = nil, model = Model.new, message = '',landscape = Landscape.new)
  @time = time
  if type.nil? || type.hex?
    @type = type
  else 
    raise ArgumentError, "Type is not a hex code."
  end
  @model = model
  @message = message
  @landscape = landscape
end

Instance Attribute Details

#landscapeObject

The landscape on which the Event exists.



545
546
547
# File 'lib/spectools.rb', line 545

def landscape
  @landscape
end

#messageObject

The event message



543
544
545
# File 'lib/spectools.rb', line 543

def message
  @message
end

#modelObject

The Model the event was asserted against



541
542
543
# File 'lib/spectools.rb', line 541

def model
  @model
end

#timeObject

The time of the event This time is local!



537
538
539
# File 'lib/spectools.rb', line 537

def time
  @time
end

#typeObject

The event’s type (or Event ID)



539
540
541
# File 'lib/spectools.rb', line 539

def type
  @type
end

Class Method Details

.cli_find(type = :all, mh_or_lh = nil, limit = 2000, evformat = false, session = nil) ⇒ Object

Use CLI to find Events. Returns an array of Event objects. Available find types:

  • :all - Retrieve all events.

  • :model - Retrieve all events for a given model.

  • If set, mh_or_lh must be a valid Model or a model handle.

  • :landscape - Retrieve all events for a given landscape.

  • If set, mh_or_lh must be a valid Landscape or a landscape handle.

Options:

  • limit - Set the maximum number of events to retrieve.

  • Default is 2000, Setting to :all is equivalent to setting to 10000

  • evformat - If set to true, populate the Events with the event message.



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
# File 'lib/vnmsh.rb', line 790

def self.cli_find(type=:all,mh_or_lh=nil,limit=2000,evformat=false,session=nil)
  session = VNMSH.get_session(session)
  events = Array.new
  event_output = session.show_events(type,mh_or_lh,limit,evformat)
  event_output.each do |line|
    if line =~ /^\d\d\/\d\d\/\d\d\d\d/
      event = Event.parse(line)
      if type == :landscape
        if mh_or_lh.kind_of?(Landscape)
          event.landscape = mh_or_lh
        else
          event.landscape = Landscape.new(mh_or_lh)
        end
      else
        event.landscape = session.current_landscape
      end
      events.push(event)
    else
      events.last.message = events.last.message + line
    end
  end
  return events
  
end

.cli_parse(line) ⇒ Object

Take a line of CLI show output and populate a new Event object.



767
768
769
770
771
772
773
774
775
776
777
778
# File 'lib/vnmsh.rb', line 767

def self.cli_parse(line)
  event = Event.new
  date,time,type,mhandle,mname,mtname,evformat = line.chomp.unpack('A10A12A12A12A1025A15A4096')
  month,day,year = date.split(/\//)
  hour,min,sec = time.split(/:/)
  event.time = Time.local(year,month,day,hour,min,sec)
  event.type = type
  event.model.handle = mhandle
  event.model.name = mname
  event.model.type.name = mtname
  return event
end