Class: FormatEngine::Engine
- Inherits:
-
Object
- Object
- FormatEngine::Engine
- Defined in:
- lib/format_engine/engine.rb
Overview
The engine class of the format engine.
Instance Attribute Summary collapse
-
#library ⇒ Object
readonly
The parse library.
-
#unparsed ⇒ Object
readonly
Any un-parsed string data.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Get an entry from the library.
-
#[]=(index, value) ⇒ Object
Set an entry in the library.
-
#do_format(src, format_spec_str) ⇒ Object
Do the actual work of building the formatted output.
-
#do_parse(src, dst, parse_spec_str) ⇒ Object
Do the actual work of parsing the formatted input.
-
#initialize(library) ⇒ Engine
constructor
Set up base data structures.
Constructor Details
#initialize(library) ⇒ Engine
Set up base data structures.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/format_engine/engine.rb', line 13 def initialize(library) @library = library @spec_pool = {} @unparsed = "" #Set up defaults for pre and post amble blocks. nop = lambda { } @library[:before] ||= nop @library[:after] ||= nop end |
Instance Attribute Details
#library ⇒ Object (readonly)
The parse library
7 8 9 |
# File 'lib/format_engine/engine.rb', line 7 def library @library end |
#unparsed ⇒ Object (readonly)
Any un-parsed string data.
10 11 12 |
# File 'lib/format_engine/engine.rb', line 10 def unparsed @unparsed end |
Instance Method Details
#[](index) ⇒ Object
Get an entry from the library
25 26 27 |
# File 'lib/format_engine/engine.rb', line 25 def [](index) @library[index] end |
#[]=(index, value) ⇒ Object
Set an entry in the library
30 31 32 |
# File 'lib/format_engine/engine.rb', line 30 def []=(index, value) @library[index] = value end |
#do_format(src, format_spec_str) ⇒ Object
Do the actual work of building the formatted output.
Parameters
-
src - The source object being formatted.
-
format_spec_str - The format specification string.
38 39 40 41 42 43 44 |
# File 'lib/format_engine/engine.rb', line 38 def do_format(src, format_spec_str) spec_info = SpecInfo.new(src, "", self) due_process(spec_info, format_spec_str) do |format| spec_info.do_format(format) end end |
#do_parse(src, dst, parse_spec_str) ⇒ Object
Do the actual work of parsing the formatted input.
Parameters
-
src - The source string being parsed.
-
dst - The class of the object being created.
-
parse_spec_str - The format specification string.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/format_engine/engine.rb', line 51 def do_parse(src, dst, parse_spec_str) spec_info = SpecInfo.new(src, dst, self) due_process(spec_info, parse_spec_str) do |format| spec_info.do_parse(format) end ensure @unparsed = spec_info.src end |