Class: CukeModeler::Background

Inherits:
Model
  • Object
show all
Includes:
Described, Named, Parsed, Parsing, Sourceable, Stepped
Defined in:
lib/cuke_modeler/models/background.rb

Overview

A class modeling a feature’s background.

Instance Attribute Summary collapse

Attributes included from Sourceable

#source_column, #source_line

Attributes included from Stepped

#steps

Attributes included from Described

#description

Attributes included from Named

#name

Attributes included from Parsed

#parsing_data

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Parsing

dialects, parse_text

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Background

Creates a new Background object and, if source_text is provided, populates the object.

Examples:

Background.new
Background.new("Background:\n  * a step")

Parameters:

  • source_text (String) (defaults to: nil)

    The Gherkin text that will be used to populate the model

Raises:

  • (ArgumentError)

    If source_text is not a String



28
29
30
31
32
# File 'lib/cuke_modeler/models/background.rb', line 28

def initialize(source_text = nil)
  @steps = []

  super
end

Instance Attribute Details

#keywordObject

The background’s keyword



15
16
17
# File 'lib/cuke_modeler/models/background.rb', line 15

def keyword
  @keyword
end

Instance Method Details

#==(other) ⇒ Boolean

Compares this model with another object. Returns true if the two objects have equivalent steps and false otherwise.

Examples:

background_1 == background_2

Parameters:

  • other (Object)

    The object to compare this model with

Returns:

  • (Boolean)

    Whether the two objects are equivalent



45
46
47
48
49
# File 'lib/cuke_modeler/models/background.rb', line 45

def ==(other)
  return false unless other.respond_to?(:steps)

  steps == other.steps
end

#childrenArray<Step>

Returns the model objects that are children of this model. For a Background model, these would be any associated Step models.

Examples:

background.children

Returns:

  • (Array<Step>)

    A collection of child models



58
59
60
# File 'lib/cuke_modeler/models/background.rb', line 58

def children
  steps
end

#inspect(verbose: false) ⇒ String

See ‘Object#inspect`. Returns some basic information about the object, including its class, object ID, and its most meaningful attribute. For a Background model, this will be the name of the background. If verbose is true, provides default Ruby inspection behavior instead.

Examples:

background.inspect
background.inspect(verbose: true)

Parameters:

  • verbose (Boolean) (defaults to: false)

    Whether or not to return the full details of the object. Defaults to false.

Returns:

  • (String)

    A string representation of this model



93
94
95
96
97
# File 'lib/cuke_modeler/models/background.rb', line 93

def inspect(verbose: false)
  return super if verbose

  "#{super.chop} @name: #{name.inspect}>"
end

#to_sString

Returns a string representation of this model. For a Background model, this will be Gherkin text that is equivalent to the background being modeled.

Examples:

background.to_s

Returns:

  • (String)

    A string representation of this model



69
70
71
72
73
74
75
76
77
78
# File 'lib/cuke_modeler/models/background.rb', line 69

def to_s
  text = ''

  text << "#{@keyword}:#{name_output_string}"
  text << "\n#{description_output_string}" unless no_description_to_output?
  text << "\n" unless steps.empty? || no_description_to_output?
  text << "\n#{steps_output_string}" unless steps.empty?

  text
end