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
-
#cache ⇒ String, ...
readonly
Cached String representation.
Instance Method Summary collapse
-
#cache_filled? ⇒ true, false
Tells if a String representation is cached or not.
-
#cache_string(options = {}) ⇒ String
protected
Defines the algorithm to construct the String representation from cache.
-
#generate_string(options = {}) ⇒ String
protected
abstract
Defines the algorithm to generate a String representation from scratch.
-
#inspect ⇒ String
A String representation for debugging purposes.
-
#invalidate_cache! ⇒ Aef::Hosts::Element
Deletes the cached String representation.
-
#to_s(options = {}) ⇒ Object
Provides a String representation of the element.
Instance Attribute Details
#cache ⇒ String, ... (readonly)
Cached String representation
36 37 38 |
# File 'lib/aef/hosts/element.rb', line 36 def cache @cache end |
Instance Method Details
#cache_filled? ⇒ true, false
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 |
#cache_string(options = {}) ⇒ String (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 |
#generate_string(options = {}) ⇒ String (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 |
#inspect ⇒ String
A String representation for debugging purposes
57 58 59 |
# File 'lib/aef/hosts/element.rb', line 57 def inspect generate_inspect(self, :cache) end |
#invalidate_cache! ⇒ Aef::Hosts::Element
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 |
#to_s(options = {}) ⇒ Object
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 |