Module: Card::Name::All::Descendants
- Included in:
- Card::Name::All
- Defined in:
- lib/card/name/all/descendants.rb
Overview
Card methods for finding name children, eg A+B is a child of A and B
Instance Method Summary collapse
-
#child_ids(side = nil) ⇒ Object
eg, A+B is a child of A and B.
- #each_child ⇒ Object
- #each_descendant(&block) ⇒ Object
- #field_ids ⇒ Object
- #field_names ⇒ Object
-
#fields ⇒ Object
NOTE: for all these helpers, method returns all fields/children/descendants.
Instance Method Details
#child_ids(side = nil) ⇒ Object
eg, A+B is a child of A and B
29 30 31 32 33 34 35 |
# File 'lib/card/name/all/descendants.rb', line 29 def child_ids side=nil return [] unless id side ||= name.simple? ? :part : :left_id Auth.as_bot do Card.search({ side => id, return: :id, limit: 0 }, "children of #{name}") end end |
#each_child ⇒ Object
21 22 23 24 25 26 |
# File 'lib/card/name/all/descendants.rb', line 21 def each_child child_ids.each do |id| (child = Card[id]) && yield(child) # check should not be needed (remove after fixing data problems) end end |
#each_descendant(&block) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/card/name/all/descendants.rb', line 37 def each_descendant &block each_child do |child| yield child child.each_descendant(&block) end end |
#field_ids ⇒ Object
17 18 19 |
# File 'lib/card/name/all/descendants.rb', line 17 def field_ids child_ids :left end |
#field_names ⇒ Object
13 14 15 |
# File 'lib/card/name/all/descendants.rb', line 13 def field_names field_ids.map { |id| Card::Name[id] } end |
#fields ⇒ Object
NOTE: for all these helpers, method returns all fields/children/descendants. (Not just those current user has permission to read.)
9 10 11 |
# File 'lib/card/name/all/descendants.rb', line 9 def fields field_ids.map { |id| Card[id] } end |