lib/haiti.rb in haiti-hash-1.1.0 vs lib/haiti.rb in haiti-hash-1.1.1
- old
+ new
@@ -9,10 +9,11 @@
# The global Hash Identifier class
class HashIdentifier
# Constants
include Version
PROTOTYPES = JSON.parse(File.read(File.join(__dir__, '../data/prototypes.json')))
+ COMMONS = JSON.parse(File.read(File.join(__dir__, '../data/commons.json')))
# @return [String] the hash (as provided)
# @example
# '5f4dcc3b5aa765d61d8327deb882cf99'
attr_reader :hash
@@ -24,10 +25,11 @@
# A new instance of hash identifier
# @param hash [String] the hash to identify
def initialize(hash)
@hash = hash
@type = identify(hash)
+ sort_commons
end
private
# Check which hash types are matching the provided hash
@@ -43,7 +45,12 @@
prototype['modes'].each do |mode|
res << Chf.new(mode)
end
end
return res
+ end
+
+ # Sort common hash types first
+ def sort_commons
+ @type.sort_by! { |e| COMMONS.include?(e.name) ? 0 : 1 }
end
end