Class: Yardstick::Measurement

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

Overview

A measurement given a constraint on the docs

Instance Method Summary collapse

Constructor Details

#initialize(rule) ⇒ Yardstick::Measurement

Return a Measurement instance

Examples:

measurement = Measurement.new(document, rule)

Parameters:


18
19
20
21
22
# File 'lib/yardstick/measurement.rb', line 18

def initialize(rule)
  @document = rule.document
  @rule     = rule
  @result   = measure
end

Instance Method Details

#descriptionString

Return the Measurement description

Examples:

measurement.description  # => "The description"

Returns:

  • (String)

    the description


82
83
84
# File 'lib/yardstick/measurement.rb', line 82

def description
  @rule.class.description
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


36
37
38
# File 'lib/yardstick/measurement.rb', line 36

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)

67
68
69
70
71
# File 'lib/yardstick/measurement.rb', line 67

def puts(io = $stdout)
  unless ok?
    io.puts("#{@document.file}:#{@document.line}: #{@document.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


52
53
54
# File 'lib/yardstick/measurement.rb', line 52

def skip?
  @result == :skip
end