Sha256: c8b293854ca3a369e113dcec4c78e1b87cafcf9cb4eb8645f2fdddb13706b2c0
Contents?: true
Size: 1.15 KB
Versions: 65
Compression:
Stored size: 1.15 KB
Contents
require_relative "contact_repository" class ContactManager class ContactManagerPresenter attr_accessor :results @@contact_attributes = [:first_name, :last_name, :email] @@contact_attributes.each {|attribute_name| attr_accessor attribute_name} def initialize(contact_repository = nil) @contact_repository = contact_repository || ContactRepository.new @results = [] end def list self.results = @contact_repository.find({}) end def find filter_map = {} @@contact_attributes.each do |attribute_name| filter_map[attribute_name] = self.send(attribute_name) if self.send(attribute_name) end self.results = @contact_repository.find(filter_map) @sort_attribute_name = nil @sort_direction_ascending = nil end def toggle_sort(attribute_name) @sort_attribute_name = attribute_name @sort_direction_ascending = !@sort_direction_ascending sorted_results = self.results.sort_by {|contact| contact.send(attribute_name).downcase} sorted_results = sorted_results.reverse unless @sort_direction_ascending self.results = sorted_results end end end
Version data entries
65 entries across 65 versions & 1 rubygems