Class: FormatEngine::FormatLiteral
- Inherits:
-
Object
- Object
- FormatEngine::FormatLiteral
- Defined in:
- lib/format_engine/format_spec/literal.rb
Overview
A format engine literal specification.
Instance Attribute Summary collapse
-
#literal ⇒ Object
readonly
The literal text of this literal specification.
Instance Method Summary collapse
-
#do_format(spec_info) ⇒ Object
Format onto the output string.
-
#do_parse(spec_info) ⇒ Object
Parse from the input string.
-
#initialize(literal) ⇒ FormatLiteral
constructor
Set up a literal format specification.
-
#inspect ⇒ Object
Inspect for debugging.
-
#validate(_engine) ⇒ Object
Is this format item supported by the engine’s library?.
-
#width ⇒ Object
The width parameter.
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.gsub(/\\./) {|seq| seq[-1]} @head = @literal.rstrip @has_tail = @head != @literal end |
Instance Attribute Details
#literal ⇒ Object (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
27 28 29 |
# File 'lib/format_engine/format_spec/literal.rb', line 27 def do_format(spec_info) spec_info.dst << @literal end |
#do_parse(spec_info) ⇒ Object
Parse from the input string
32 33 34 35 |
# File 'lib/format_engine/format_spec/literal.rb', line 32 def do_parse(spec_info) spec_info.parse!(@head) unless @head.empty? spec_info.parse(/\s*/) if @has_tail end |
#inspect ⇒ Object
Inspect for debugging.
38 39 40 |
# File 'lib/format_engine/format_spec/literal.rb', line 38 def inspect "Literal(#{literal.inspect})" end |
#validate(_engine) ⇒ Object
Is this format item supported by the engine’s library?
22 23 24 |
# File 'lib/format_engine/format_spec/literal.rb', line 22 def validate(_engine) true end |
#width ⇒ Object
The width parameter. Handled literally so this is always zero.
17 18 19 |
# File 'lib/format_engine/format_spec/literal.rb', line 17 def width 0 end |