Class: Usher::Delimiters

Inherits:
Array
  • Object
show all
Defined in:
lib/usher/delimiters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ary) ⇒ Delimiters

Returns a new instance of Delimiters.



6
7
8
9
10
11
# File 'lib/usher/delimiters.rb', line 6

def initialize(ary)
  super ary
  @unescaped = self.map do |delimiter|
    (delimiter[0] == ?\\) ? delimiter[1..-1] : delimiter
  end
end

Instance Attribute Details

#unescapedObject (readonly)

Returns the value of attribute unescaped.



4
5
6
# File 'lib/usher/delimiters.rb', line 4

def unescaped
  @unescaped
end

Instance Method Details

#first_in(array) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/usher/delimiters.rb', line 13

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