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

Version Path
glimmer-dsl-opal-0.29.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.28.3 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.28.2 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.28.1 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.28.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.27.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.26.3 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.26.2 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.26.1 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.26.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.25.4 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.25.3 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.25.2 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.25.1 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.25.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.24.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.23.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.22.1 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.22.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb
glimmer-dsl-opal-0.21.0 lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_manager_presenter.rb