Sha256: b8aeb8494052cef93e8b5d5a9a0d9572749e183d7607e086fa9176d1d6409761

Contents?: true

Size: 528 Bytes

Versions: 2

Compression:

Stored size: 528 Bytes

Contents

class Delimiters < Array

  attr_reader :unescaped
  
  def initialize(ary)
    super ary
    @unescaped = self.map do |delimiter|
      (delimiter[0] == ?\\) ? delimiter[1..-1] : delimiter
    end
  end
  
  def first_in(array)
    # TODO: should we optimize this O(n*m)? hash or modified or KNP or at leaset sort + b-search. But they are so short

    array.each do |element|
      return element if self.unescaped.any? { |delimiter| delimiter == element }
    end
    nil    
  end

  # TODO: Delimiters#regex and so on  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
usher-0.5.13 lib/usher/delimiters.rb
usher-0.5.12 lib/usher/delimiters.rb