Class: Usher::Delimiters
- Inherits:
-
Array
- Object
- Array
- Usher::Delimiters
- Defined in:
- lib/usher/delimiters.rb
Overview
Array of delimiters with convenience methods.
Instance Attribute Summary collapse
-
#unescaped ⇒ Object
readonly
Returns the value of attribute unescaped.
Instance Method Summary collapse
-
#first_in(array) ⇒ nil, String
Finds the first occurrance of a delimiter in an array.
-
#initialize(ary) ⇒ Delimiters
constructor
Creates a list of delimiters.
-
#regexp ⇒ Regexp
The regular expression to find the delimiters.
-
#regexp_char_class ⇒ String
The regular expression expressed as a character class.
Constructor Details
#initialize(ary) ⇒ Delimiters
Creates a list of delimiters
9 10 11 12 13 14 |
# File 'lib/usher/delimiters.rb', line 9 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.
5 6 7 |
# File 'lib/usher/delimiters.rb', line 5 def unescaped @unescaped end |
Instance Method Details
#first_in(array) ⇒ nil, String
Finds the first occurrance of a delimiter in an array
19 20 21 |
# File 'lib/usher/delimiters.rb', line 19 def first_in(array) array.find { |e| e if unescaped.any? { |delimiter| delimiter == e } } end |
#regexp ⇒ Regexp
The regular expression to find the delimiters.
25 26 27 |
# File 'lib/usher/delimiters.rb', line 25 def regexp @regexp ||= Regexp.new("(#{unescaped.collect{|d| Regexp.quote(d)}.join('|')})") end |
#regexp_char_class ⇒ String
The regular expression expressed as a character class.
31 32 33 |
# File 'lib/usher/delimiters.rb', line 31 def regexp_char_class @regexp_char_class ||= collect{|d| Regexp.quote(d)}.join end |