Class: Arugula::LiteralPart

Inherits:
Part
  • Object
show all
Defined in:
lib/arugula/parts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Part

all, inherited, type

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

#literalObject

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_sObject



23
24
25
# File 'lib/arugula/parts.rb', line 23

def to_s
  literal.gsub('\\', '\\\\').gsub(/[.]/) { |m| "\\#{m}" }
end