class Gherkin::GherkinLine

Attributes

indent[R]
trimmed_line_text[R]

Public Class Methods

new(line_text, line_number) click to toggle source
# File lib/gherkin/gherkin_line.rb, line 4
def initialize(line_text, line_number)
  @line_text = line_text
  @line_number = line_number
  @trimmed_line_text = @line_text.lstrip
  @indent = @line_text.length - @trimmed_line_text.length
end

Public Instance Methods

empty?() click to toggle source
# File lib/gherkin/gherkin_line.rb, line 23
def empty?
  @trimmed_line_text.empty?
end
get_line_text(indent_to_remove) click to toggle source
# File lib/gherkin/gherkin_line.rb, line 27
def get_line_text(indent_to_remove)
  indent_to_remove ||= 0
  if indent_to_remove < 0 || indent_to_remove > indent
    @trimmed_line_text
  else
    @line_text[indent_to_remove..-1]
  end
end
get_rest_trimmed(length) click to toggle source
# File lib/gherkin/gherkin_line.rb, line 19
def get_rest_trimmed(length)
  @trimmed_line_text[length..-1].strip
end
split_table_cells(row) { |cell, start_col| ... } click to toggle source
# File lib/gherkin/gherkin_line.rb, line 48
def split_table_cells(row)
  col = 0
  start_col = col + 1
  cell = ''
  first_cell = true
  while col < row.length
    char = row[col]
    col += 1
    if char == '|'
      if first_cell
        # First cell (content before the first |) is skipped
        first_cell = false
      else
        yield cell, start_col
      end
      cell = ''
      start_col = col + 1
    elsif char == '\'
      char = row[col]
      col += 1
      if char == 'n'
        cell += "\n"
      else
        cell += '\' unless ['|', '\'].include?(char)
        cell += char
      end
    else
      cell += char
    end
  end
  # Last cell (content after the last |) is skipped
end
start_with?(prefix) click to toggle source
# File lib/gherkin/gherkin_line.rb, line 11
def start_with?(prefix)
  @trimmed_line_text.start_with?(prefix)
end
start_with_title_keyword?(keyword) click to toggle source
# File lib/gherkin/gherkin_line.rb, line 15
def start_with_title_keyword?(keyword)
  start_with?(keyword+':') # The C# impl is more complicated. Find out why.
end
table_cells() click to toggle source
# File lib/gherkin/gherkin_line.rb, line 36
def table_cells
  cells = []

  self.split_table_cells(@trimmed_line_text) do |item, column|
    cell_indent = item.length - item.lstrip.length
    span = Span.new(@indent + column + cell_indent, item.strip)
    cells.push(span)
  end

  cells
end
tags() click to toggle source
# File lib/gherkin/gherkin_line.rb, line 81
def tags
  column = @indent + 1;
  items = @trimmed_line_text.strip.split('@')
  items = items[1..-1] # ignore before the first @
  items.map do |item|
    length = item.length
    span = Span.new(column, '@' + item.strip)
    column += length + 1
    span
  end
end