Sha256: 2fb1a86752b14c6b87d6b3940491071880ea4061db0cf6ebfef97905bbcd50fd

Contents?: true

Size: 578 Bytes

Versions: 11

Compression:

Stored size: 578 Bytes

Contents

class Usher
  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
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
usher-0.7.1 lib/usher/delimiters.rb
usher-0.7.0 lib/usher/delimiters.rb
usher-0.6.8 lib/usher/delimiters.rb
usher-0.6.7 lib/usher/delimiters.rb
usher-0.6.6 lib/usher/delimiters.rb
usher-0.6.5 lib/usher/delimiters.rb
usher-0.6.4 lib/usher/delimiters.rb
usher-0.6.3 lib/usher/delimiters.rb
usher-0.6.2 lib/usher/delimiters.rb
usher-0.6.1 lib/usher/delimiters.rb
usher-0.6.0 lib/usher/delimiters.rb