module Card::Name::All::Descendants

Card methods for finding name children, eg A+B is a child of A and B

Public Instance Methods

child_ids(side=nil) click to toggle source

eg, A+B is a child of A and B

# File lib/card/name/all/descendants.rb, line 32
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() { |card| ... } click to toggle source
# File lib/card/name/all/descendants.rb, line 21
def each_child
  return unless id

  sql = "(left_id = #{id} or right_id = #{id}) and trash is false"
  Card.where(sql).find_each do |card|
    card.include_set_modules
    yield card
  end
end
each_descendant() { |child| ... } click to toggle source
# File lib/card/name/all/descendants.rb, line 41
def each_descendant &block
  each_child do |child|
    yield child
    child.each_descendant(&block)
  end
end
field_cards() click to toggle source

NOTE: for all these helpers, method returns all fields/children/descendants. (Not just those current user has permission to read.)

# File lib/card/name/all/descendants.rb, line 9
def field_cards
  field_ids.map(&:card)
end
field_ids() click to toggle source
# File lib/card/name/all/descendants.rb, line 17
def field_ids
  child_ids :left
end
field_names() click to toggle source
# File lib/card/name/all/descendants.rb, line 13
def field_names
  field_ids.map(&:cardname)
end