Class: Arugula::LiteralPart
Instance Attribute Summary collapse
-
#literal ⇒ Object
Returns the value of attribute literal.
Instance Method Summary collapse
-
#initialize(literal) ⇒ LiteralPart
constructor
A new instance of LiteralPart.
- #match(str, index, _match_data) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Part
Constructor Details
#initialize(literal) ⇒ LiteralPart
Returns a new instance of LiteralPart.
19 20 21 |
# File 'lib/arugula/parts.rb', line 19 def initialize(literal) @literal = literal end |
Instance Attribute Details
#literal ⇒ Object
Returns the value of attribute literal.
18 19 20 |
# File 'lib/arugula/parts.rb', line 18 def literal @literal end |
Instance Method Details
#match(str, index, _match_data) ⇒ Object
27 28 29 30 31 |
# File 'lib/arugula/parts.rb', line 27 def match(str, index, _match_data) length = literal.size matches = str[index, length] == literal [matches, index + (matches ? length : 0)] end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/arugula/parts.rb', line 23 def to_s literal.gsub('\\', '\\\\').gsub(/[.]/) { |m| "\\#{m}" } end |