Class: DataMapper::Collection

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

Instance Method Summary collapse

Instance Method Details

#analyzeObject



26
27
28
29
30
# File 'lib/ptj/ext/datamapper_collection.rb', line 26

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

#analyze_and_sortObject



16
17
18
19
20
21
22
23
24
# File 'lib/ptj/ext/datamapper_collection.rb', line 16

def analyze_and_sort
  b = Hash.new(0)
  self.each do |item|
    meth = item.method(entry)
    b[meth.call()] += 1
  end
  b = b.sort_by { |k,v| -1*v }
  b
end

#get_value(entry) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/ptj/ext/datamapper_collection.rb', line 7

def get_value(entry)
  returned_array = []
  self.each do |item|
    meth = item.method(entry)
    returned_array << meth.call()
  end
  returned_array
end

#sort_by_occurance(entry) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/ptj/ext/datamapper_collection.rb', line 32

def sort_by_occurance(entry)
  returned_array = []
  sorted_array = self.analyze_and_sort(entry)
  sorted_array.each do |smaller_array|
    returned_array << smaller_array[0]
  end
  returned_array
end