Sha256: 42088e5336c982b9f5938a508092439c16b041b07f2a562d66bd2c7a0324c85f

Contents?: true

Size: 992 Bytes

Versions: 4

Compression:

Stored size: 992 Bytes

Contents

module Gherkin
  module Format
    class Argument
      attr_reader :byte_offset, :val

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gherkin-1.0.3-i386-mswin32 lib/gherkin/format/argument.rb
gherkin-1.0.3-i386-mingw32 lib/gherkin/format/argument.rb
gherkin-1.0.3-java lib/gherkin/format/argument.rb
gherkin-1.0.3 lib/gherkin/format/argument.rb