Class: Aef::Hosts::Element Abstract
- Inherits:
-
Object
- Object
- Aef::Hosts::Element
- Defined in:
- lib/aef/hosts/element.rb
Overview
This class is not supposed to be instantiated.
The base class for elements which are aggregated by the Aef::Hosts::File class.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (String, ...) cache
readonly
Cached String representation.
Instance Method Summary (collapse)
-
- (true, false) cache_filled?
Tells if a String representation is cached or not.
-
- (String) cache_string(options = {})
protected
Defines the algorithm to construct the String representation from cache.
-
- (String) generate_string(options = {})
protected
abstract
Defines the algorithm to generate a String representation from scratch.
-
- (String) inspect
A String representation for debugging purposes.
-
- (Aef::Hosts::Element) invalidate_cache!
Deletes the cached String representation.
-
- (Object) to_s(options = {})
Provides a String representation of the element.
Instance Attribute Details
- (String, ...) cache (readonly)
Cached String representation
36 37 38 |
# File 'lib/aef/hosts/element.rb', line 36 def cache @cache end |
Instance Method Details
- (true, false) cache_filled?
Tells if a String representation is cached or not
50 51 52 |
# File 'lib/aef/hosts/element.rb', line 50 def cache_filled? @cache ? true : false end |
- (String) cache_string(options = {}) (protected)
Defines the algorithm to construct the String representation from cache
101 102 103 |
# File 'lib/aef/hosts/element.rb', line 101 def cache_string( = {}) @cache.dup end |
- (String) generate_string(options = {}) (protected)
This method needs to be implemented in descendant classes.
Defines the algorithm to generate a String representation from scratch.
94 95 96 |
# File 'lib/aef/hosts/element.rb', line 94 def generate_string( = {}) raise NotImplementedError end |
- (String) inspect
A String representation for debugging purposes
57 58 59 |
# File 'lib/aef/hosts/element.rb', line 57 def inspect generate_inspect(self, :cache) end |
- (Aef::Hosts::Element) invalidate_cache!
Deletes the cached String representation
41 42 43 44 45 |
# File 'lib/aef/hosts/element.rb', line 41 def invalidate_cache! @cache = nil self end |
- (Object) to_s(options = {})
Provides a String representation of the element
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/aef/hosts/element.rb', line 70 def to_s( = {}) (, :force_generation, :linebreak_encoding) string = '' if !cache_filled? || [:force_generation] string << generate_string() else string << cache_string() end if [:linebreak_encoding] string = Aef::Linebreak.encode(string, [:linebreak_encoding]) end string end |