Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/ptj/ext/datamapper_collection.rb

Instance Method Summary collapse

Instance Method Details

#analyzeObject



45
46
47
48
49
# File 'lib/ptj/ext/datamapper_collection.rb', line 45

def analyze
  h = Hash.new(0)
  self.each { | v | h.store(v, h[v]+1) }
  h
end

#analyze_and_sortObject



51
52
53
54
55
56
# File 'lib/ptj/ext/datamapper_collection.rb', line 51

def analyze_and_sort
  b = Hash.new(0)
  self.each { | v | b.store(v, b[v]+1) }
  b = b.sort_by { |k,v| -1*v }
  b
end

#analyze_and_sort_keyObject



58
59
60
61
62
63
# File 'lib/ptj/ext/datamapper_collection.rb', line 58

def analyze_and_sort_key
  b = Hash.new(0)
  self.each { | v | b.store(v, b[v]+1) }
  b = b.sort_by { |k,v| k }
  b
end