class CukeModeler::Model

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

Public Class Methods

new(source_text = nil) click to toggle source

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

@example

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

@param source_text [String] The string that will be used to populate the model. Defaults to nil. @raise [ArgumentError] If source_text is not a String @return [Model] A new Model instance

# 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

Public Instance Methods

children() click to toggle source

Returns the model objects that are children of this model.

@example

model.children

@return [Array<Model>] A collection of child models

# File lib/cuke_modeler/models/model.rb, line 53
def children
  []
end
inspect(verbose: false) click to toggle source

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.

@example

model.inspect
model.inspect(verbose: true)

@param verbose [Boolean] Whether or not to return the full details of

the object. Defaults to false.

@return [String] A string representation of this model

Calls superclass method
# File lib/cuke_modeler/models/model.rb, line 68
def inspect(verbose: false)
  return super() if verbose

  "#<#{self.class.name}:#{object_id}>"
end
to_s() click to toggle source

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

@example

model.to_s

@return [String] A string representation of this model

Calls superclass method
# File lib/cuke_modeler/models/model.rb, line 41
def to_s
  super
end

Private Instance Methods

populate_model(model_data) click to toggle source
# File lib/cuke_modeler/models/model.rb, line 82
def populate_model(model_data)
  # No-op. Overridden by child classes.
end
process_source(source_text) click to toggle source
# File lib/cuke_modeler/models/model.rb, line 78
def process_source(source_text)
  # No-op. Overridden by child classes.
end