Class: Enf::Elephant
- Inherits:
-
Object
- Object
- Enf::Elephant
- Defined in:
- lib/enf/elephant.rb,
lib/enf/elephant/fetch_service.rb
Overview
Represent a node of the graph
Direct Known Subclasses
Defined Under Namespace
Classes: CannotRegister, FetchService, Nope
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#default_leave_value ⇒ Object
readonly
Returns the value of attribute default_leave_value.
-
#leave ⇒ Object
Returns the value of attribute leave.
Instance Method Summary collapse
- #include?(element) ⇒ Boolean
-
#initialize(default_leave_value = false) ⇒ Elephant
constructor
A new instance of Elephant.
- #register!(element, payload = true) ⇒ Object
Constructor Details
#initialize(default_leave_value = false) ⇒ Elephant
12 13 14 15 16 |
# File 'lib/enf/elephant.rb', line 12 def initialize(default_leave_value = false) @default_leave_value = default_leave_value self.leave = default_leave_value @children = Hash.new { |hash, key| hash[key] = Elephant.new } end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
9 10 11 |
# File 'lib/enf/elephant.rb', line 9 def children @children end |
#default_leave_value ⇒ Object (readonly)
Returns the value of attribute default_leave_value.
9 10 11 |
# File 'lib/enf/elephant.rb', line 9 def default_leave_value @default_leave_value end |
#leave ⇒ Object
Returns the value of attribute leave.
10 11 12 |
# File 'lib/enf/elephant.rb', line 10 def leave @leave end |
Instance Method Details
#include?(element) ⇒ Boolean
36 37 38 39 |
# File 'lib/enf/elephant.rb', line 36 def include?(element) return default_leave_value if Input.invalid?(element) FetchService.search_in(self, element) { neutral_node }.leave end |
#register!(element, payload = true) ⇒ Object
18 19 20 21 22 |
# File 'lib/enf/elephant.rb', line 18 def register!(element, payload = true) fail CannotRegister if frozen? || Input.invalid?(element) return (self.leave = payload) if element.empty? children[element[0]].register!(element[1..-1]) end |