Module: Inform::Genealogical
- Included in:
- Ephemeral::Object
- Defined in:
- lib/story_teller/tree.rb
Overview
The Genealogical module
Instance Method Summary collapse
- #>(other) ⇒ Object
- #all?(*args, &block) ⇒ Boolean
- #any?(*args, &block) ⇒ Boolean
- #branch ⇒ Object
-
#child(o = self, prop = :@children) ⇒ Object
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/MethodLength rubocop: disable Metrics/PerceivedComplexity.
-
#children(o = nil, prop = :@children) ⇒ Object
rubocop: disable Metrics/AbcSize.
- #collect(*args, &block) ⇒ Object
- #concat(*args, &block) ⇒ Object
- #count(*args, &block) ⇒ Object
- #delete_if(*args, &block) ⇒ Object
- #each(*args, &block) ⇒ Object
- #each_with_object(*args, &block) ⇒ Object
- #find(*args, &block) ⇒ Object
- #find_all(*args, &block) ⇒ Object
- #having(method) ⇒ Object
- #in?(*others) ⇒ Boolean
-
#include?(other) ⇒ Boolean
TODO: Refactor all of these to use Ruby Sequel dataset methods.
- #map(*args, &block) ⇒ Object
- #notin?(*others) ⇒ Boolean
- #reject(*args, &block) ⇒ Object
- #select(*args, &block) ⇒ Object
-
#sibling(o = self) ⇒ Object
rubocop: enable Metrics/AbcSize rubocop: enable Metrics/CyclomaticComplexity rubocop: enable Metrics/MethodLength rubocop: enable Metrics/PerceivedComplexity.
- #siblings(orphanage = false) ⇒ Object
- #within?(*others) ⇒ Boolean
Instance Method Details
#>(other) ⇒ Object
28 29 30 |
# File 'lib/story_teller/tree.rb', line 28 def >(other) self << other end |
#all?(*args, &block) ⇒ Boolean
72 73 74 |
# File 'lib/story_teller/tree.rb', line 72 def all?(*args, &block) self.children.all?(*args, &block) end |
#any?(*args, &block) ⇒ Boolean
76 77 78 |
# File 'lib/story_teller/tree.rb', line 76 def any?(*args, &block) self.children.any?(*args, &block) end |
#branch ⇒ Object
68 69 70 |
# File 'lib/story_teller/tree.rb', line 68 def branch [self] + self.descendants end |
#child(o = self, prop = :@children) ⇒ Object
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/CyclomaticComplexity rubocop: disable Metrics/MethodLength rubocop: disable Metrics/PerceivedComplexity
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/story_teller/tree.rb', line 148 def child(o = self, prop = :@children) if o.instance_variable_defined?(prop) # The idea here is that o may be an Inform::Ephemeral::Object. children = o.instance_variable_get(prop) return nil unless children.respond_to?(:first) children.first elsif o.respond_to?(:children_dataset) # It may be necessary to find some way of caching # the parent-children relationship. Therefore, # the following benchmarking is a way to gather # data so that it might be determined whether # enabling caching makes any difference in # execution speed. begin # TODO: Remove: if defined?(DEBUG) && @parser_trace >= 12 log.debug "#{indent}#{self}.children_dataset execution -- BEGIN" end # TODO: Remove: start = Time.now return o.children_dataset.first ensure # TODO: Remove # TODO: Remove elapsed = Time.now - start if defined? DEBUG # TODO: Remove: if defined?(DEBUG) && @parser_trace >= 12 log.debug "#{indent}#{self}.children_dataset executed in #{elapsed.round(6)} milliseconds" end end else log.warn "Object #{o} <#{o.identity}> (#{o.class}) has no children accessor" nil end end |
#children(o = nil, prop = :@children) ⇒ Object
rubocop: disable Metrics/AbcSize
129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/story_teller/tree.rb', line 129 def children(o = nil, prop = :@children) # TODO: Remove unless o.nil? log.warn "In genealogical.children(#{o})" log.warn " #{o}.respond_to? :children_dataset #=> #{o.respond_to? :children_dataset}" log.warn " #{o}.instance_variable_defined?(#{prop}) #=> #{o.respond_to? :children_dataset}" end self.safe_refresh if self.respond_to?(:safe_refresh) o.safe_refresh if o.respond_to?(:safe_refresh) return children.length if o.respond_to? :children_dataset return o.instance_variable_get(prop).length if o.instance_variable_defined?(prop) super() end |
#collect(*args, &block) ⇒ Object
92 93 94 |
# File 'lib/story_teller/tree.rb', line 92 def collect(*args, &block) self.children.collect(*args, &block) end |
#concat(*args, &block) ⇒ Object
120 121 122 |
# File 'lib/story_teller/tree.rb', line 120 def concat(*args, &block) self.children.concat(*args, &block) end |
#count(*args, &block) ⇒ Object
104 105 106 |
# File 'lib/story_teller/tree.rb', line 104 def count(*args, &block) self.children.count(*args, &block) end |
#delete_if(*args, &block) ⇒ Object
100 101 102 |
# File 'lib/story_teller/tree.rb', line 100 def delete_if(*args, &block) self.children.delete_if(*args, &block) end |
#each(*args, &block) ⇒ Object
80 81 82 |
# File 'lib/story_teller/tree.rb', line 80 def each(*args, &block) self.children.each(*args, &block) end |
#each_with_object(*args, &block) ⇒ Object
84 85 86 |
# File 'lib/story_teller/tree.rb', line 84 def each_with_object(*args, &block) self.children.each_with_object(*args, &block) end |
#find(*args, &block) ⇒ Object
112 113 114 |
# File 'lib/story_teller/tree.rb', line 112 def find(*args, &block) self.children.find(*args, &block) end |
#find_all(*args, &block) ⇒ Object
116 117 118 |
# File 'lib/story_teller/tree.rb', line 116 def find_all(*args, &block) self.children.find_all(*args, &block) end |
#having(method) ⇒ Object
124 125 126 |
# File 'lib/story_teller/tree.rb', line 124 def having(method) self.children.having(method) end |
#in?(*others) ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/story_teller/tree.rb', line 40 def in?(*others) return false unless self.respond_to?(:parent) self.refresh if self.respond_to?(:refresh) x = self.parent x.refresh if x.respond_to?(:refresh) return others.include?(x) if others.length > 1 y = others.first return true if self.parent == y return false unless y.respond_to?(:include?) y.include?(self) end |
#include?(other) ⇒ Boolean
TODO: Refactor all of these to use Ruby Sequel dataset methods.
34 35 36 37 38 |
# File 'lib/story_teller/tree.rb', line 34 def include?(other) other.refresh if other.respond_to?(:refresh) return true if other.parent == self self.children.include?(other) end |
#map(*args, &block) ⇒ Object
108 109 110 |
# File 'lib/story_teller/tree.rb', line 108 def map(*args, &block) self.children.map(*args, &block) end |
#notin?(*others) ⇒ Boolean
64 65 66 |
# File 'lib/story_teller/tree.rb', line 64 def notin?(*others) !self.in?(*others) end |
#reject(*args, &block) ⇒ Object
96 97 98 |
# File 'lib/story_teller/tree.rb', line 96 def reject(*args, &block) self.children.reject(*args, &block) end |
#select(*args, &block) ⇒ Object
88 89 90 |
# File 'lib/story_teller/tree.rb', line 88 def select(*args, &block) self.children.select(*args, &block).to_a end |
#sibling(o = self) ⇒ Object
rubocop: enable Metrics/AbcSize rubocop: enable Metrics/CyclomaticComplexity rubocop: enable Metrics/MethodLength rubocop: enable Metrics/PerceivedComplexity
187 188 189 190 191 192 193 194 195 |
# File 'lib/story_teller/tree.rb', line 187 def sibling(o = self) o.refresh if o.respond_to? :refresh return nil if o.parent.nil? parent = o.parent return nil unless parent.respond_to?(:children) children = o.parent.children return nil if children.nil? || children.empty? children[children.index(o) + 1] end |
#siblings(orphanage = false) ⇒ Object
197 198 199 200 201 202 203 |
# File 'lib/story_teller/tree.rb', line 197 def siblings(orphanage = false) if self.parent.nil? return orphanage ? Inform::Object.roots : [] end self.refresh if self.respond_to? :refresh self.parent.children - [self] end |
#within?(*others) ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/story_teller/tree.rb', line 52 def within?(*others) x = self x.refresh if x.respond_to?(:refresh) loop do x = x.parent break if x.nil? return true if others.include?(x) x.refresh if x.respond_to?(:refresh) end false end |