Module: BrowserOfBabel::Holotheca::Holarchy Private
- Included in:
- BrowserOfBabel::Holotheca
- Defined in:
- lib/browser_of_babel/holotheca/holarchy.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Methods related to manipulating hierarachy of holathecas.
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
- #identifier ⇒ Any readonly private
- #parent ⇒ Holotheca? readonly private
Instance Method Summary collapse
-
#depth ⇒ Integer
private
Get depth of this holotheca in the holarchy, starting from #root.
-
#dig(*identifiers) ⇒ Object
private
Go down several levels, following a string of identifiers.
-
#down(identifier) ⇒ Holotheca
private
Go down a level to holotheca called
identifier. - #initialize(parent, identifier) ⇒ Object private
-
#path ⇒ Array<Holotheca>
private
Get holothecas from the top level to this one.
-
#path_identifiers ⇒ Array<Any>
(also: #deconstruct)
private
Get identifiers of all holothecas in the #path.
-
#root ⇒ Holotheca
private
Get the root holotheca.
-
#up(levels = 1) ⇒ Holotheca
private
Go up
levelsnumber of times.
Instance Attribute Details
#identifier ⇒ Any (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 82 def identifier @identifier end |
#parent ⇒ Holotheca? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 80 def parent @parent end |
Instance Method Details
#depth ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get depth of this holotheca in the holarchy, starting from #root.
105 106 107 108 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 105 def depth @depth ||= enumerate_parents.reduce(0) { |count, e| e.parent ? count + 1 : (break count) } end |
#dig(*identifiers) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Go down several levels, following a string of identifiers.
157 158 159 160 161 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 157 def dig(*identifiers) return self if !identifiers || identifiers.empty? down(identifiers.first).dig(*identifiers[1..]) end |
#down(identifier) ⇒ Holotheca
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Go down a level to holotheca called identifier.
It is an error to go below the lowest level.
145 146 147 148 149 150 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 145 def down(identifier) child_class = self.class.child_class raise InvalidHolothecaError, "nowhere to go down" unless child_class child_class.new(self, identifier) end |
#initialize(parent, identifier) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
84 85 86 87 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 84 def initialize(parent, identifier) @parent = parent @identifier = identifier end |
#path ⇒ Array<Holotheca>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get holothecas from the top level to this one.
91 92 93 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 91 def path @path ||= enumerate_parents.take_while(&:itself).reverse! end |
#path_identifiers ⇒ Array<Any> Also known as: deconstruct
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get identifiers of all holothecas in the #path.
97 98 99 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 97 def path_identifiers path.map(&:identifier) end |
#root ⇒ Holotheca
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the root holotheca.
112 113 114 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 112 def root @root ||= enumerate_parents.find { _1.parent.nil? } end |
#up(levels = 1) ⇒ Holotheca
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Go up levels number of times.
There is no penalty for trying to escape from the top level.
123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/browser_of_babel/holotheca/holarchy.rb', line 123 def up(levels = 1) levels = levels.to_int raise ArgumentError, "levels must be non-negative" if levels.negative? return self unless parent return self if levels.zero? parent.up(levels - 1) rescue NoMethodError => e raise unless e.name == :to_int raise ArgumentError, "no implicit conversion of #{levels.class} to Integer" end |