Sha256: a4ec1cde52e133e1a2f58acde952568ab749829b762f24a7245da4a229793b9e

Contents?: true

Size: 885 Bytes

Versions: 66

Compression:

Stored size: 885 Bytes

Contents

# encoding: utf-8

module Familyable
  # Familynize
  #
  # this module require id, parent_ids fileds.
  module Familynize
    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

    def get_children(person)
      family.reduce([]) do |ret, v|
        ret << v if v.parent_ids.include?(person.id)
        ret
      end
    end

    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
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/familyable/familynize.rb
tbpgr_utils-0.0.150 lib/familyable/familynize.rb
tbpgr_utils-0.0.149 lib/familyable/familynize.rb
tbpgr_utils-0.0.148 lib/familyable/familynize.rb
tbpgr_utils-0.0.147 lib/familyable/familynize.rb
tbpgr_utils-0.0.146 lib/familyable/familynize.rb
tbpgr_utils-0.0.145 lib/familyable/familynize.rb
tbpgr_utils-0.0.144 lib/familyable/familynize.rb
tbpgr_utils-0.0.143 lib/familyable/familynize.rb
tbpgr_utils-0.0.142 lib/familyable/familynize.rb
tbpgr_utils-0.0.141 lib/familyable/familynize.rb
tbpgr_utils-0.0.140 lib/familyable/familynize.rb
tbpgr_utils-0.0.139 lib/familyable/familynize.rb
tbpgr_utils-0.0.138 lib/familyable/familynize.rb
tbpgr_utils-0.0.137 lib/familyable/familynize.rb
tbpgr_utils-0.0.136 lib/familyable/familynize.rb
tbpgr_utils-0.0.135 lib/familyable/familynize.rb
tbpgr_utils-0.0.134 lib/familyable/familynize.rb
tbpgr_utils-0.0.133 lib/familyable/familynize.rb
tbpgr_utils-0.0.132 lib/familyable/familynize.rb