Class: ContactManager::ContactRepository
- Inherits:
-
Object
- Object
- ContactManager::ContactRepository
- Defined in:
- lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_repository.rb
Constant Summary collapse
- NAMES_FIRST =
%w[ Liam Noah William James Oliver Benjamin Elijah Lucas Mason Logan Alexander Ethan Jacob Michael Daniel Henry Jackson Sebastian Aiden Matthew Samuel David Joseph Carter Owen Wyatt John Jack Luke Jayden Dylan Grayson Levi Isaac Gabriel Julian Mateo Anthony Jaxon Lincoln Joshua Christopher Andrew Theodore Caleb Ryan Asher Nathan Thomas Leo Isaiah Charles Josiah Hudson Christian Hunter Connor Eli Ezra Aaron Landon Adrian Jonathan Nolan Jeremiah Easton Elias Colton Cameron Carson Robert Angel Maverick Nicholas Dominic Jaxson Greyson Adam Ian Austin Santiago Jordan Cooper Brayden Roman Evan Ezekiel Xaviar Jose Jace Jameson Leonardo Axel Everett Kayden Miles Sawyer Jason Emma Olivia ]
- NAMES_LAST =
%w[ Smith Johnson Williams Brown Jones Miller Davis Wilson Anderson Taylor ]
Instance Method Summary collapse
- #find(attribute_filter_map) ⇒ Object
-
#initialize(contacts = nil) ⇒ ContactRepository
constructor
A new instance of ContactRepository.
Constructor Details
#initialize(contacts = nil) ⇒ ContactRepository
Returns a new instance of ContactRepository.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_repository.rb', line 142 def initialize(contacts = nil) @contacts = contacts || 100.times.map do |n| random_first_name_index = (rand*NAMES_FIRST.size).to_i random_last_name_index = (rand*NAMES_LAST.size).to_i first_name = NAMES_FIRST[random_first_name_index] last_name = NAMES_LAST[random_last_name_index] email = "#{first_name}@#{last_name}.com".downcase Contact.new( first_name: first_name, last_name: last_name, email: email ) end end |
Instance Method Details
#find(attribute_filter_map) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/glimmer-dsl-opal/samples/elaborate/contact_manager/contact_repository.rb', line 157 def find(attribute_filter_map) @contacts.find_all do |contact| match = true attribute_filter_map.keys.each do |attribute_name| contact_value = contact.send(attribute_name).downcase filter_value = attribute_filter_map[attribute_name].downcase match = false unless contact_value.match(filter_value) end match end end |