Module: Familyable::Familynize
- Included in:
- Family
- Defined in:
- lib/familyable/familynize.rb
Overview
Familynize
this module require id, parent_ids fileds.
Instance Method Summary collapse
Instance Method Details
#get_brothers(person) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/familyable/familynize.rb', line 28 def get_brothers(person) ret = [] tmp_family = family.dup person.parent_ids.each do |parent_id| tmp_family.each do |v| next if v == person next unless v.parent_ids.include?(parent_id) ret << v tmp_family.delete(v) end end ret end |
#get_children(person) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/familyable/familynize.rb', line 21 def get_children(person) family.reduce([]) do |ret, v| ret << v if v.parent_ids.include?(person.id) ret end end |
#get_parents(person) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/familyable/familynize.rb', line 8 def get_parents(person) ret = [] tmp_family = family.dup person.parent_ids.each do |parent_id| tmp_family.each do |v| next unless v.id == parent_id ret << v tmp_family.delete(v) end end ret end |