Class: FormatEngine::FormatLiteral

Inherits:
Object
  • Object
show all
Defined in:
lib/format_engine/format_spec/literal.rb

Overview

A format engine literal specification.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(literal) ⇒ FormatLiteral

Set up a literal format specification.



10
11
12
13
14
# File 'lib/format_engine/format_spec/literal.rb', line 10

def initialize(literal)
  @literal = literal
  @head = literal.rstrip
  @tail = @head != @literal
end

Instance Attribute Details

#literalObject (readonly)

The literal text of this literal specification.



7
8
9
# File 'lib/format_engine/format_spec/literal.rb', line 7

def literal
  @literal
end

Instance Method Details

#do_format(spec_info) ⇒ Object

Format onto the output string



22
23
24
# File 'lib/format_engine/format_spec/literal.rb', line 22

def do_format(spec_info)
  spec_info.dst << @literal
end

#do_parse(spec_info) ⇒ Object

Parse from the input string



27
28
29
30
# File 'lib/format_engine/format_spec/literal.rb', line 27

def do_parse(spec_info)
  spec_info.parse!(@head) unless @head.empty?
  spec_info.parse(/\s*/)  if @tail
end

#inspectObject

Inspect for debugging.



33
34
35
# File 'lib/format_engine/format_spec/literal.rb', line 33

def inspect
  "Literal(#{literal.inspect})"
end

#validate(_engine) ⇒ Object

Is this literal supported by the engine? YES!



17
18
19
# File 'lib/format_engine/format_spec/literal.rb', line 17

def validate(_engine)
  self
end