Class: SortedSeeder::Seeder::SeederSorter

Inherits:
Object
  • Object
show all
Defined in:
lib/sorted_seeder/seeder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seed_base_object) ⇒ SeederSorter

Returns a new instance of SeederSorter.



13
14
15
# File 'lib/sorted_seeder/seeder.rb', line 13

def initialize(seed_base_object)
  @seed_base_object = seed_base_object
end

Instance Attribute Details

#seed_base_objectObject

Returns the value of attribute seed_base_object.



11
12
13
# File 'lib/sorted_seeder/seeder.rb', line 11

def seed_base_object
  @seed_base_object
end

Instance Method Details

#<=>(other_object) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sorted_seeder/seeder.rb', line 17

def <=>(other_object)
  compare_value = nil
  compare_value = (@seed_base_object <=> other_object.seed_base_object) if @seed_base_object.respond_to?(:<=>)

  unless compare_value
    compare_value = (other_object.seed_base_object <=> @seed_base_object) if other_object.seed_base_object.respond_to?(:<=>)

    if compare_value
      compare_value = -1 * compare_value
    else
      if other_object.seed_base_object.is_a?(Class)
        if seed_base_object.is_a?(Class)
          compare_value = (seed_base_object.name <=> other_object.seed_base_object.name)
        else
          compare_value = -1
        end
      else
        if seed_base_object.is_a?(Class)
          compare_value = 1
        else
          compare_value = 0
        end
      end
    end
  end

  compare_value
end