OTWO-1213 Works around lost encoding in Ruby/C binding layer
[ohcount] / ruby / gestalt / base.rb
1 module Ohcount
2   module Gestalt
3
4     class Base
5       attr_reader :type, :name, :count
6
7       def initialize(type, name, count = 1)
8         @type = type
9         @name = name
10         @count = count
11       end
12
13       def ==(other)
14         other.type.to_s == self.type.to_s &&
15           other.name == self.name &&
16           other.count == self.count
17       end
18
19       def <=>(other)
20                                 # Sort by type, then descending count, then name
21                                 if self.type != other.type
22                                         self.type.to_s <=> other.type.to_s
23                                 elsif self.count != other.count
24                                         -(self.count <=> other.count)
25                                 else
26                                         self.name.to_s <=> other.name.to_s
27                                 end     
28       end
29
30       # will return an array of detected gestalts from a source_file_list
31       def self.find_gestalts(source_file_list)
32         GestaltEngine.new.process(source_file_list).gestalts
33       end
34
35     end
36   end
37 end