Class: CukeModeler::Model

Inherits:
Object
  • Object
show all
Includes:
Containing, Nested
Defined in:
lib/cuke_modeler/models/model.rb

Overview

A class modeling an element of a Cucumber suite. All model classes should descend from this class.

Instance Attribute Summary

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Model

Creates a new Model object and, if source_text is provided, populates the object. For the base model class, there is nothing to populate.

Examples:

Model.new
Model.new('some source text')

Parameters:

  • source_text (String) (defaults to: nil)

    The string that will be used to populate the model. Defaults to nil.

Raises:

  • (ArgumentError)

    If source_text is not a String



21
22
23
24
25
26
27
28
29
# File 'lib/cuke_modeler/models/model.rb', line 21

def initialize(source_text = nil)
  error_message = "Can only create models from Strings but was given a #{source_text.class}."
  raise(ArgumentError, error_message) if source_text && !source_text.is_a?(String)

  return unless source_text

  source_data = process_source(source_text)
  populate_model(source_data)
end

Instance Method Details

#childrenArray<Model>

Returns the model objects that are children of this model.

Examples:

model.children

Returns:

  • (Array<Model>)

    A collection of child models



53
54
55
# File 'lib/cuke_modeler/models/model.rb', line 53

def children
  []
end

#inspect(verbose: false) ⇒ String

See ‘Object#inspect`. Returns some basic information about the object, including its class and object ID. If verbose is true, provides default Ruby inspection behavior instead.

Examples:

model.inspect
model.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



68
69
70
71
72
# File 'lib/cuke_modeler/models/model.rb', line 68

def inspect(verbose: false)
  return super() if verbose

  "#<#{self.class.name}:#{object_id}>"
end

#to_sString

Returns a string representation of this model. Because the base model class doesn’t represent anything specific, its string output is undefined.

Examples:

model.to_s

Returns:

  • (String)

    A string representation of this model



41
42
43
# File 'lib/cuke_modeler/models/model.rb', line 41

def to_s
  super
end