Class: Perforator::Meter

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

Constant Summary collapse

NoExpectedTimeError =
Class.new(StandardError)
NotCallableCallbackError =
Class.new(StandardError)
NotFixnumExpectedTimeError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Meter

Returns a new instance of Meter.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/perforator.rb', line 12

def initialize(options = {})
  @name              = options.fetch(:name,              nil)
  @logger            = options.fetch(:logger,            nil)
  @process_puts      = options.fetch(:puts,            false)
  @expected_time     = options.fetch(:expected_time,     nil)
  @positive_callback = options.fetch(:positive_callback, nil)
  @negative_callback = options.fetch(:negative_callback, nil)

  raise NoExpectedTimeError if callbacks_without_expected_time?
  raise NotFixnumExpectedTimeError unless expected_time_valid?
  raise NotCallableCallbackError unless callable_callbacks?
end

Instance Attribute Details

#expected_timeObject (readonly)

Returns the value of attribute expected_time.



9
10
11
# File 'lib/perforator.rb', line 9

def expected_time
  @expected_time
end

#finish_timeObject (readonly)

Returns the value of attribute finish_time.



9
10
11
# File 'lib/perforator.rb', line 9

def finish_time
  @finish_time
end

#loggerObject (readonly) Also known as: process_logger?

Returns the value of attribute logger.



9
10
11
# File 'lib/perforator.rb', line 9

def logger
  @logger
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/perforator.rb', line 9

def name
  @name
end

#negative_callbackObject (readonly)

Returns the value of attribute negative_callback.



9
10
11
# File 'lib/perforator.rb', line 9

def negative_callback
  @negative_callback
end

#positive_callbackObject (readonly)

Returns the value of attribute positive_callback.



9
10
11
# File 'lib/perforator.rb', line 9

def positive_callback
  @positive_callback
end

#spent_timeObject (readonly)

Returns the value of attribute spent_time.



9
10
11
# File 'lib/perforator.rb', line 9

def spent_time
  @spent_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



9
10
11
# File 'lib/perforator.rb', line 9

def start_time
  @start_time
end

Instance Method Details

#call {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



25
26
27
28
29
30
31
# File 'lib/perforator.rb', line 25

def call(&block)
  start

  yield(self)

  finish
end

#log!(content) ⇒ Object



33
34
35
# File 'lib/perforator.rb', line 33

def log!(content)
  log_items << content
end