Class: Yardstick::Measurement

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

Overview

A measurement given a constraint on the docs

Defined Under Namespace

Modules: UtilityMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, docstring) { ... } ⇒ Yardstick::Measurement

Return a Measurement instance

Examples:

measurement = Measurement.new('The description', docstring, :successful_method)

Parameters:

  • description (#to_str)

    the measurement description

  • docstring (YARD::Docstring)

    the docstring to measure

Yields:

  • the measurement to perform



44
45
46
47
48
49
# File 'lib/yardstick/measurement.rb', line 44

def initialize(description, docstring, &block)
  @description = description.to_str
  @docstring   = docstring
  @block       = block
  @result      = measure
end

Instance Attribute Details

#descriptionString (readonly)

Return the Measurement description

Examples:

measurement.description  # => "The description"

Returns:

  • (String)

    the description



17
18
19
# File 'lib/yardstick/measurement.rb', line 17

def description
  @description
end

Instance Method Details

#eql?(other) ⇒ Boolean

Test if Measurement is equal to another measurement

Examples:

measurement == equal_measurement  # => true

Parameters:

Returns:

  • (Boolean)

    true if the Measurement is equal to the other, false if not



128
129
130
131
132
# File 'lib/yardstick/measurement.rb', line 128

def eql?(other)
  other.kind_of?(self.class) &&
  description.eql?(other.description) &&
  docstring.eql?(other.docstring)
end

#hashInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return hash identifier for the Measurement

Returns:

  • (Integer)

    the hash identifier



140
141
142
# File 'lib/yardstick/measurement.rb', line 140

def hash
  description.hash ^ docstring.hash
end

#ok?Boolean

Return true if the measurement was successful

Examples:

Measurement successful

measurement.ok?  # => true

Measurement unsuccessful

measurement.ok?  # => false

Returns:

  • (Boolean)

    true if the measurement was successful, false if not



63
64
65
# File 'lib/yardstick/measurement.rb', line 63

def ok?
  @result == true || skip?
end

#puts(io = $stdout) ⇒ undefined

Warns the results the measurement if it was not successful

Examples:

measurement.puts  # (outputs results if not successful)

Parameters:

  • io (#puts) (defaults to: $stdout)

    optional object to puts the summary

Returns:

  • (undefined)


110
111
112
113
114
# File 'lib/yardstick/measurement.rb', line 110

def puts(io = $stdout)
  unless ok?
    io.puts("#{file}:#{line}: #{path}: #{description}")
  end
end

#skip?Boolean

Return true if the measurement was skipped

Examples:

Measurement skipped

measurement.skip?  # => true

Measurement not skipped

measurement.skip?  # => false

Returns:

  • (Boolean)

    true if the measurement was skipped, false if not



79
80
81
# File 'lib/yardstick/measurement.rb', line 79

def skip?
  @result == :skip
end

#todo?Boolean

Return true if the measurement is not implemented

Examples:

Measurement not implemented

measurement.todo?  # => true

Measurement implemented

measurement.todo?  # => false

Returns:

  • (Boolean)

    true if the measurement is not implemented, false if not



95
96
97
# File 'lib/yardstick/measurement.rb', line 95

def todo?
  @result == :todo
end