Class: CukeModeler::Cell

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

Overview

A class modeling a single cell of a row.

Instance Attribute Summary collapse

Attributes included from Parsed

#parsing_data

Attributes included from Sourceable

#source_column, #source_line

Attributes included from Nested

#parent_model

Instance Method Summary collapse

Methods included from Parsing

dialects, parse_text

Methods inherited from Model

#children

Methods included from Containing

#each, #each_descendant, #each_model

Methods included from Nested

#get_ancestor

Constructor Details

#initialize(source_text = nil) ⇒ Cell

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

Examples:

Cell.new
Cell.new('some value')

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



25
26
27
# File 'lib/cuke_modeler/models/cell.rb', line 25

def initialize(source_text = nil)
  super(source_text)
end

Instance Attribute Details

#valueObject

The value of the cell



12
13
14
# File 'lib/cuke_modeler/models/cell.rb', line 12

def value
  @value
end

Instance Method Details

#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 Cell model, this will be the value of the cell. If verbose is true, provides default Ruby inspection behavior instead.

Examples:

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



54
55
56
57
58
# File 'lib/cuke_modeler/models/cell.rb', line 54

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

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

#to_sString

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

Examples:

cell.to_s

Returns:

  • (String)

    A string representation of this model



36
37
38
39
# File 'lib/cuke_modeler/models/cell.rb', line 36

def to_s
  # Vertical bars and backslashes are special characters that need to be escaped
  @value ? @value.gsub('\\', '\\\\\\').gsub('|', '\|') : ''
end