Sha256: 1fdef00931ac875fd7f5ea2eaef1c359c9b35da3c2794e84182fbfe1a6429818
Contents?: true
Size: 691 Bytes
Versions: 29
Compression:
Stored size: 691 Bytes
Contents
module Onoma class Variety < Onoma::Record::Base TOPLEVEL_VARIETIES = %w[bioproduct immatter matter product product_group].freeze class << self def parent_variety(variety) v = find(variety) if v.nil? nil elsif (toplevel = toplevel_parent(v)).present? toplevel.name else v.name end end def toplevel_parent(variety) ancestors(variety).last end def ancestors(variety) if variety.parent.nil? || TOPLEVEL_VARIETIES.include?(variety.parent.name) [] else [variety.parent, *ancestors(variety.parent)] end end end end end
Version data entries
29 entries across 29 versions & 1 rubygems