Module: Treat::Entities::Entity::Comparable
- Included in:
- Treat::Entities::Entity
- Defined in:
- lib/treat/entities/entity/comparable.rb
Overview
Allow comparison of entity hierarchy in DOM.
Instance Method Summary collapse
-
#compare_with(klass) ⇒ Object
Determines whether the receiving class is smaller, equal or greater in the DOM hierarchy compared to the supplied one.
Instance Method Details
#compare_with(klass) ⇒ Object
Determines whether the receiving class is smaller, equal or greater in the DOM hierarchy compared to the supplied one.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/treat/entities/entity/comparable.rb', line 7 def compare_with(klass) i = 0; rank_a = nil; rank_b = nil Treat.core.entities.order.each do |type| klass2 = Treat::Entities.const_get(type.cc) rank_a = i if self <= klass2 rank_b = i if klass <= klass2 next if rank_a && rank_b i += 1 end return -1 if rank_a < rank_b return 0 if rank_a == rank_b return 1 if rank_a > rank_b end |