Class: Usher::Delimiters
- Inherits:
-
Array
- Object
- Array
- Usher::Delimiters
- Defined in:
- lib/usher/delimiters.rb
Instance Attribute Summary collapse
-
#unescaped ⇒ Object
readonly
Returns the value of attribute unescaped.
Instance Method Summary collapse
- #first_in(array) ⇒ Object
-
#initialize(ary) ⇒ Delimiters
constructor
A new instance of Delimiters.
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
#unescaped ⇒ Object (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 |