Class: Gherkin::Formatter::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/formatter/argument.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(byte_offset, val) ⇒ Argument

Returns a new instance of Argument.



9
10
11
# File 'lib/gherkin/formatter/argument.rb', line 9

def initialize(byte_offset, val)
  @byte_offset, @val = byte_offset, val
end

Instance Attribute Details

#byte_offsetObject (readonly)

Returns the value of attribute byte_offset.



7
8
9
# File 'lib/gherkin/formatter/argument.rb', line 7

def byte_offset
  @byte_offset
end

#valObject (readonly)

Returns the value of attribute val.



7
8
9
# File 'lib/gherkin/formatter/argument.rb', line 7

def val
  @val
end

Class Method Details

.format(string, argument_format, arguments) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gherkin/formatter/argument.rb', line 13

def self.format(string, argument_format, arguments)
  arguments ||= []
  s = string.dup
  offset = past_offset = 0
  arguments.each do |arg|
    next if arg.byte_offset.nil? || arg.byte_offset < past_offset
    replacement = argument_format.format_argument(arg.val)
    s[arg.byte_offset + offset, arg.val.length] = replacement
    offset += replacement.unpack("U*").length - arg.val.unpack("U*").length
    past_offset = arg.byte_offset + arg.val.length
  end
  s
end