Module: ODDB::Html::Util::Sort

Included in:
State::Drugs::Products, PackageSort
Defined in:
lib/oddb/html/util/sort.rb

Instance Method Summary collapse

Instance Method Details

#_sortObject



12
13
14
15
16
# File 'lib/oddb/html/util/sort.rb', line 12

def _sort
  if(key = @session.user_input(:sortvalue))
    sort_by(key.to_sym)
  end
end

#_sort_by(model, reverse, &sorter) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/oddb/html/util/sort.rb', line 27

def _sort_by(model, reverse, &sorter)
  model = model.sort_by(&sorter)
  if(reverse)
    model.reverse!
  end
  model
end

#sortObject



8
9
10
11
# File 'lib/oddb/html/util/sort.rb', line 8

def sort
  _sort
  self
end

#sort_by(key, default = '') ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/oddb/html/util/sort.rb', line 17

def sort_by(key, default='')
  sorter = sort_proc(key) || Proc.new { |pac| pac.send(key) || default }
  if(@sortvalue == key)
    @reverse = !@reverse
  else
    @reverse = false
    @sortvalue = key
  end
  @model = _sort_by(@model, @reverse, &sorter)
end

#sort_proc(key) ⇒ Object



34
35
# File 'lib/oddb/html/util/sort.rb', line 34

def sort_proc(key)
end