Sha256: defcf34b3cd944e375b36c6223f5acda29803f056da8293f8ad89a18b13be0d9

Contents?: true

Size: 696 Bytes

Versions: 6

Compression:

Stored size: 696 Bytes

Contents

class FillIN::Factory

  TAG = /^(.+\S+)\s*\((.*)\)$/

  def initialize(label, value, within: nil)
    @label = label
    @value = value
    @within = within
  end

  def call
    if in_quotes?
      remove_quotes!
    end

    if !@value.nil? && @value[':'] && !in_quotes?
      step = FillIN::ComplexInput
    elsif @label =~ TAG
      @label = $1
      tag    = $2
      step   = Pickles.config.step_by_tag(tag) || FillIN::Input
    else
      step = FillIN::Input
    end

    step.new(@label, @value, @within)
  end

private

  def in_quotes?
    @in_quotes ||= @value && @value[0] == "\"" && @value[-1] == "\""
  end

  def remove_quotes!
    @value[0]  = ''
    @value[-1] = ''
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pickles-0.2.4 lib/cucumber/pickles/steps/fill_in/factory.rb
pickles-0.2.3 lib/cucumber/pickles/steps/fill_in/factory.rb
pickles-0.2.2 lib/cucumber/pickles/steps/fill_in/factory.rb
pickles-0.2.1 lib/cucumber/pickles/steps/fill_in/factory.rb
pickles-0.2.0 lib/cucumber/pickles/steps/fill_in/factory.rb
pickles-0.1.12 lib/cucumber/pickles/steps/fill_in/factory.rb