Class: Gherkin::Format::Argument

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/format/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.



17
18
19
# File 'lib/gherkin/format/argument.rb', line 17

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.



4
5
6
# File 'lib/gherkin/format/argument.rb', line 4

def byte_offset
  @byte_offset
end

#valObject (readonly)

Returns the value of attribute val.



4
5
6
# File 'lib/gherkin/format/argument.rb', line 4

def val
  @val
end

Class Method Details

.format(string, argument_format, arguments) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gherkin/format/argument.rb', line 21

def self.format(string, argument_format, 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

.new(byte_offset, val) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/gherkin/format/argument.rb', line 7

def new(byte_offset, val)
  if defined?(JRUBY_VERSION)
    require 'gherkin.jar'
    Java::GherkinFormatter::Argument.new(byte_offset, val)
  else
    super
  end
end