Sha256: fa89ae68ff4ff83a6d55a60870ee48f3c18b4e035ce330d35e73cd26cc77ea90

Contents?: true

Size: 813 Bytes

Versions: 74

Compression:

Stored size: 813 Bytes

Contents

require 'gherkin/native'

module Gherkin
  module Formatter
    class Argument
      native_impl('gherkin')
      attr_reader :byte_offset, :val

      def initialize(byte_offset, val)
        @byte_offset, @val = byte_offset, val
      end
      
      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
    end
  end
end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
gherkin-2.2.8 lib/gherkin/formatter/argument.rb
gherkin-2.2.8-x86-mswin32 lib/gherkin/formatter/argument.rb
gherkin-2.2.8-x86-mingw32 lib/gherkin/formatter/argument.rb
gherkin-2.2.8-universal-dotnet lib/gherkin/formatter/argument.rb
gherkin-2.2.8-java lib/gherkin/formatter/argument.rb
gherkin-2.2.7 lib/gherkin/formatter/argument.rb
gherkin-2.2.7-x86-mswin32 lib/gherkin/formatter/argument.rb
gherkin-2.2.7-x86-mingw32 lib/gherkin/formatter/argument.rb
gherkin-2.2.7-universal-dotnet lib/gherkin/formatter/argument.rb
gherkin-2.2.7-java lib/gherkin/formatter/argument.rb
gherkin-2.2.6 lib/gherkin/formatter/argument.rb
gherkin-2.2.6-x86-mswin32 lib/gherkin/formatter/argument.rb
gherkin-2.2.6-x86-mingw32 lib/gherkin/formatter/argument.rb
gherkin-2.2.6-universal-dotnet lib/gherkin/formatter/argument.rb
gherkin-2.2.6-java lib/gherkin/formatter/argument.rb
gherkin-2.2.5 lib/gherkin/formatter/argument.rb
gherkin-2.2.5-x86-mswin32 lib/gherkin/formatter/argument.rb
gherkin-2.2.5-x86-mingw32 lib/gherkin/formatter/argument.rb
gherkin-2.2.5-universal-dotnet lib/gherkin/formatter/argument.rb
gherkin-2.2.5-java lib/gherkin/formatter/argument.rb