Module: PaginateAlphabetically::ClassMethods

Defined in:
lib/paginate_alphabetically.rb

Instance Method Summary collapse

Instance Method Details

#alphabetical_group(letter = nil) ⇒ Object



18
19
20
# File 'lib/paginate_alphabetically.rb', line 18

def alphabetical_group(letter = nil)
  find(:all, :conditions => ["#{@attribute.to_s} LIKE ?", "#{letter || first_letter}%"], :order => @attribute)
end

#first_letterObject



12
13
14
15
16
# File 'lib/paginate_alphabetically.rb', line 12

def first_letter
  first_instance = find(:first, :order => @attribute, :conditions => ["#{@attribute.to_s} >= ?", 'a'])
  return 'A' if first_instance.nil?
  first_instance.send(@attribute)[0].chr.upcase
end

#pagination_lettersObject



8
9
10
# File 'lib/paginate_alphabetically.rb', line 8

def pagination_letters
  all.sort_by{|obj| obj.send(@attribute).upcase}.group_by {|group| group.send(@attribute)[0].chr.upcase}.keys
end