Class: Lucid::StepMatch
Overview
:nodoc:
Instance Attribute Summary collapse
-
#step_arguments ⇒ Object
readonly
Returns the value of attribute step_arguments.
-
#step_definition ⇒ Object
readonly
Returns the value of attribute step_definition.
Instance Method Summary collapse
- #args ⇒ Object
- #backtrace_line ⇒ Object
- #file_colon_line ⇒ Object
- #format_args(format = lambda{|a| a}, &proc) ⇒ Object
-
#initialize(step_definition, name_to_match, name_to_report, step_arguments) ⇒ StepMatch
constructor
A new instance of StepMatch.
-
#inspect ⇒ Object
:nodoc:.
- #invoke(multiline_arg) ⇒ Object
- #name ⇒ Object
- #replace_arguments(string, step_arguments, format, &proc) ⇒ Object
- #text_length ⇒ Object
Constructor Details
#initialize(step_definition, name_to_match, name_to_report, step_arguments) ⇒ StepMatch
Returns a new instance of StepMatch.
5 6 7 8 9 10 11 12 |
# File 'lib/lucid/step_match.rb', line 5 def initialize(step_definition, name_to_match, name_to_report, step_arguments) raise "name_to_match can't be nil" if name_to_match.nil? raise "step_arguments can't be nil (but it can be an empty array)" if step_arguments.nil? @step_definition = step_definition @name_to_match = name_to_match @name_to_report = name_to_report @step_arguments = step_arguments end |
Instance Attribute Details
#step_arguments ⇒ Object (readonly)
Returns the value of attribute step_arguments.
3 4 5 |
# File 'lib/lucid/step_match.rb', line 3 def step_arguments @step_arguments end |
#step_definition ⇒ Object (readonly)
Returns the value of attribute step_definition.
3 4 5 |
# File 'lib/lucid/step_match.rb', line 3 def step_definition @step_definition end |
Instance Method Details
#args ⇒ Object
14 15 16 |
# File 'lib/lucid/step_match.rb', line 14 def args @step_arguments.map{|g| g.val.freeze} end |
#backtrace_line ⇒ Object
36 37 38 |
# File 'lib/lucid/step_match.rb', line 36 def backtrace_line "#{file_colon_line}:in `#{@step_definition.regexp_source}'" end |
#file_colon_line ⇒ Object
32 33 34 |
# File 'lib/lucid/step_match.rb', line 32 def file_colon_line @step_definition.file_colon_line end |
#format_args(format = lambda{|a| a}, &proc) ⇒ Object
28 29 30 |
# File 'lib/lucid/step_match.rb', line 28 def format_args(format = lambda{|a| a}, &proc) @name_to_report || replace_arguments(@name_to_match, @step_arguments, format, &proc) end |
#inspect ⇒ Object
:nodoc:
65 66 67 |
# File 'lib/lucid/step_match.rb', line 65 def inspect #:nodoc: sprintf("#<%s:0x%x>", self.class, self.object_id) end |
#invoke(multiline_arg) ⇒ Object
22 23 24 25 26 |
# File 'lib/lucid/step_match.rb', line 22 def invoke(multiline_arg) all_args = args all_args << multiline_arg.to_step_definition_arg if multiline_arg @step_definition.invoke(all_args) end |
#name ⇒ Object
18 19 20 |
# File 'lib/lucid/step_match.rb', line 18 def name @name_to_report end |
#replace_arguments(string, step_arguments, format, &proc) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lucid/step_match.rb', line 44 def replace_arguments(string, step_arguments, format, &proc) s = string.dup offset = past_offset = 0 step_arguments.each do |step_argument| next if step_argument.offset.nil? || step_argument.offset < past_offset replacement = if block_given? proc.call(step_argument.val) elsif Proc === format format.call(step_argument.val) else format % step_argument.val end s[step_argument.offset + offset, step_argument.val.length] = replacement offset += replacement.unpack('U*').length - step_argument.val.unpack('U*').length past_offset = step_argument.offset + step_argument.val.length end s end |
#text_length ⇒ Object
40 41 42 |
# File 'lib/lucid/step_match.rb', line 40 def text_length @step_definition.regexp_source.unpack('U*').length end |