glimmer-dsl-swt 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/ext/glimmer/config.rb +5 -1
- data/lib/glimmer/Rakefile +5 -0
- data/lib/glimmer/launcher.rb +31 -7
- data/lib/glimmer/rake_task.rb +97 -0
- data/samples/elaborate/contact_manager.rb +121 -0
- data/samples/elaborate/contact_manager/contact.rb +11 -0
- data/samples/elaborate/contact_manager/contact_manager_presenter.rb +26 -0
- data/samples/elaborate/contact_manager/contact_repository.rb +244 -0
- data/samples/elaborate/login.rb +108 -0
- data/samples/elaborate/tic_tac_toe.rb +55 -0
- data/samples/elaborate/tic_tac_toe/board.rb +124 -0
- data/samples/elaborate/tic_tac_toe/cell.rb +27 -0
- data/samples/hello/hello_browser.rb +8 -0
- data/samples/hello/hello_combo.rb +38 -0
- data/samples/hello/hello_computed.rb +69 -0
- data/samples/hello/hello_computed/contact.rb +21 -0
- data/samples/hello/hello_drag_and_drop.rb +29 -0
- data/samples/hello/hello_list_multi_selection.rb +48 -0
- data/samples/hello/hello_list_single_selection.rb +37 -0
- data/samples/hello/hello_menu_bar.rb +64 -0
- data/samples/hello/hello_message_box.rb +15 -0
- data/samples/hello/hello_pop_up_context_menu.rb +36 -0
- data/samples/hello/hello_tab.rb +24 -0
- data/samples/hello/hello_world.rb +8 -0
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82c0437f480a9bfc7064ec9cf10bc196a3bbb644d8fe20832c02eda79565435a
|
4
|
+
data.tar.gz: 418e810fad2c7f12280b78848931c743d619a8cc28f04f7a438092de9fed12e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dadb4107a2480af548a5e1f79f60b44a798e0ae2aa130e14dae4e1878d7211418c53ab88be39cb8adcfe42a1fc3846b46e06f5e90dccb984299896eef90f15a9
|
7
|
+
data.tar.gz: f902727a93b33a3aa0f013484b44f648fc2f991766f612ebb4e093c932389032417f8fe038de17609f7a28e3324d158419a1e502d07cd822b104658a7b4fb33c
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 0.6.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 0.6.4 (Desktop GUI)
|
2
2
|
[](http://badge.fury.io/rb/glimmer-dsl-swt)
|
3
3
|
[](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
|
4
4
|
[](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.4
|
data/lib/ext/glimmer/config.rb
CHANGED
@@ -100,7 +100,11 @@ if ENV['GLIMMER_LOGGER_LEVEL']
|
|
100
100
|
# if glimmer log level is being overridden for debugging purposes, then disable async logging making logging immediate
|
101
101
|
Glimmer::Config.logging_appender_options = Glimmer::Config.logging_appender_options.merge(async: false, auto_flushing: 1)
|
102
102
|
Glimmer::Config.logging_devices = [:stdout]
|
103
|
-
|
103
|
+
begin
|
104
|
+
Glimmer::Config.logger.level = ENV['GLIMMER_LOGGER_LEVEL'].strip
|
105
|
+
rescue => e
|
106
|
+
puts e.message
|
107
|
+
end
|
104
108
|
end
|
105
109
|
Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
|
106
110
|
method = method_symbol.to_s
|
@@ -0,0 +1,5 @@
|
|
1
|
+
# This Rakefile gets used from Glimmer::Launcher when the current directory for running the `glimmer` command
|
2
|
+
# does not have a Rakefile (e.g. during scaffolding).
|
3
|
+
# It is not needed when running from inside a scaffolded app or gem, or an app with a Rakefile that has
|
4
|
+
# `require 'glimmer/rake_task'`
|
5
|
+
require 'glimmer/rake_task'
|
data/lib/glimmer/launcher.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
1
3
|
require_relative 'rake_task'
|
2
4
|
|
3
5
|
module Glimmer
|
@@ -5,6 +7,7 @@ module Glimmer
|
|
5
7
|
OPERATING_SYSTEMS_SUPPORTED = ["mac", "windows", "linux"]
|
6
8
|
|
7
9
|
TEXT_USAGE_PREFIX = <<~MULTI_LINE_STRING
|
10
|
+
Glimmer (Ruby Desktop Development GUI Library) - JRuby Gem: glimmer-dsl-swt v#{File.read(File.expand_path('../../../VERSION', __FILE__))}
|
8
11
|
Usage: glimmer [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-jruby-option]...] (application.rb or task[task_args]) [[application2.rb]...]
|
9
12
|
|
10
13
|
Runs Glimmer applications/tasks.
|
@@ -73,6 +76,10 @@ module Glimmer
|
|
73
76
|
end
|
74
77
|
@glimmer_lib
|
75
78
|
end
|
79
|
+
|
80
|
+
def dev_mode?
|
81
|
+
glimmer_lib == GLIMMER_LIB_LOCAL
|
82
|
+
end
|
76
83
|
|
77
84
|
def glimmer_option_env_vars(glimmer_options)
|
78
85
|
GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair|
|
@@ -89,7 +96,13 @@ module Glimmer
|
|
89
96
|
def launch(application, jruby_options: [], env_vars: {}, glimmer_options: {})
|
90
97
|
jruby_options_string = jruby_options.join(' ') + ' ' if jruby_options.any?
|
91
98
|
env_vars = env_vars.merge(glimmer_option_env_vars(glimmer_options))
|
92
|
-
env_vars_string = env_vars.map
|
99
|
+
env_vars_string = env_vars.map do |k,v|
|
100
|
+
if OS.windows? && ENV['PROMPT'] # detect command prompt (or powershell)
|
101
|
+
"set #{k}=#{v} && "
|
102
|
+
else
|
103
|
+
"export #{k}=#{v} && "
|
104
|
+
end
|
105
|
+
end.join
|
93
106
|
the_glimmer_lib = glimmer_lib
|
94
107
|
devmode_require = nil
|
95
108
|
if the_glimmer_lib == GLIMMER_LIB_LOCAL
|
@@ -113,8 +126,16 @@ module Glimmer
|
|
113
126
|
puts "Launching Glimmer Application: #{application}" if jruby_options_string.to_s.include?('--debug') || glimmer_options['--quiet'].to_s.downcase != 'true'
|
114
127
|
end
|
115
128
|
command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
|
129
|
+
if !env_vars_string.empty? && OS.windows?
|
130
|
+
command = "bash -c \"#{command}\"" if ENV['SHELL'] # do in Windows Git Bash only
|
131
|
+
command = "cmd /C \"#{command}\"" if ENV['PROMPT'] # do in Windows Command Prompt only (or Powershell)
|
132
|
+
end
|
116
133
|
puts command if jruby_options_string.to_s.include?('--debug')
|
117
|
-
|
134
|
+
if command.include?(' irb ')
|
135
|
+
exec command
|
136
|
+
else
|
137
|
+
system command
|
138
|
+
end
|
118
139
|
end
|
119
140
|
end
|
120
141
|
end
|
@@ -159,11 +180,14 @@ module Glimmer
|
|
159
180
|
end
|
160
181
|
|
161
182
|
def display_usage
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
183
|
+
rakefile_dir = File.exist?('Rakefile') ? '.' : File.dirname(__FILE__)
|
184
|
+
FileUtils.cd(rakefile_dir) do
|
185
|
+
rake_tasks = `rake -T`.gsub('rake glimmer:', 'glimmer ').split("\n").select {|l| l.start_with?('glimmer ')}
|
186
|
+
puts TEXT_USAGE_PREFIX
|
187
|
+
puts rake_tasks.join("\n")
|
188
|
+
puts TEXT_USAGE_SUFFIX
|
189
|
+
end
|
190
|
+
end
|
167
191
|
|
168
192
|
def extract_application_paths(options)
|
169
193
|
options.select do |option|
|
data/lib/glimmer/rake_task.rb
CHANGED
@@ -3,6 +3,103 @@ require 'rake'
|
|
3
3
|
require_relative 'package'
|
4
4
|
|
5
5
|
namespace :glimmer do
|
6
|
+
namespace :sample do
|
7
|
+
desc 'Runs a Glimmer internal sample [included in gem]. If no name is supplied, it runs all samples.'
|
8
|
+
task :run, [:name] => :requires do |t, args|
|
9
|
+
name = args[:name]
|
10
|
+
name = name.underscore.downcase unless name.nil?
|
11
|
+
samples = (Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)) + Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__))).sort
|
12
|
+
samples = samples.select {|path| path.include?("#{name}.rb")} unless name.nil?
|
13
|
+
Rake::Task['glimmer:sample:code'].invoke(name) if samples.size == 1
|
14
|
+
Glimmer::Launcher.new(samples << '--quiet=false').launch
|
15
|
+
end
|
16
|
+
|
17
|
+
namespace :run do
|
18
|
+
task :hello do
|
19
|
+
samples = Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)).sort
|
20
|
+
Glimmer::Launcher.new(samples << '--quiet=false').launch
|
21
|
+
end
|
22
|
+
|
23
|
+
task :elaborate do
|
24
|
+
samples = Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__)).sort
|
25
|
+
Glimmer::Launcher.new(samples << '--quiet=false').launch
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Lists Glimmer internal samples [included in gem]. Filters by query if specified (query is optional)'
|
30
|
+
task :list, [:query] do |t, args|
|
31
|
+
Rake::Task['glimmer:sample:list:hello'].invoke(args[:query])
|
32
|
+
Rake::Task['glimmer:sample:list:elaborate'].invoke(args[:query])
|
33
|
+
end
|
34
|
+
|
35
|
+
namespace :list do
|
36
|
+
task :hello, [:query] => :requires do |t, args|
|
37
|
+
array_of_arrays = Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)).map do |path|
|
38
|
+
File.basename(path, '.rb')
|
39
|
+
end.select do |path|
|
40
|
+
args[:query].nil? || path.include?(args[:query])
|
41
|
+
end.map do |path|
|
42
|
+
[path, path.underscore.titlecase, "#{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run[#{path}]"]
|
43
|
+
end.sort
|
44
|
+
puts
|
45
|
+
puts " Glimmer Hello Samples (run all via: #{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run:hello):"
|
46
|
+
puts Text::Table.new(
|
47
|
+
:head => %w[Name Description Run],
|
48
|
+
:rows => array_of_arrays,
|
49
|
+
:horizontal_padding => 1,
|
50
|
+
:vertical_boundary => ' ',
|
51
|
+
:horizontal_boundary => ' ',
|
52
|
+
:boundary_intersection => ' '
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
task :elaborate, [:query] => :requires do |t, args|
|
57
|
+
array_of_arrays = Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__)).map do |path|
|
58
|
+
File.basename(path, '.rb')
|
59
|
+
end.select do |path|
|
60
|
+
args[:query].nil? || path.include?(args[:query])
|
61
|
+
end.map do |path|
|
62
|
+
[path, path.underscore.titlecase, "#{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run[#{path}]"]
|
63
|
+
end.sort
|
64
|
+
puts
|
65
|
+
puts " Glimmer Elaborate Samples (run all via: #{'bin/' if Glimmer::Launcher.dev_mode?}glimmer sample:run:elaborate):"
|
66
|
+
puts Text::Table.new(
|
67
|
+
:head => %w[Name Description Run],
|
68
|
+
:rows => array_of_arrays,
|
69
|
+
:horizontal_padding => 1,
|
70
|
+
:vertical_boundary => ' ',
|
71
|
+
:horizontal_boundary => ' ',
|
72
|
+
:boundary_intersection => ' '
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
desc 'Outputs code for a Glimmer internal sample [included in gem] (name is required)'
|
78
|
+
task :code, [:name] => :requires do |t, args|
|
79
|
+
samples = (Dir.glob(File.expand_path('../../../samples/hello/*.rb', __FILE__)) + Dir.glob(File.expand_path('../../../samples/elaborate/*.rb', __FILE__))).sort
|
80
|
+
sample = samples.detect {|path| path.include?("#{args[:name].to_s.underscore.downcase}.rb")}
|
81
|
+
sample_additional_files = Dir.glob(File.join(sample.sub('.rb', ''), '**', '*.rb'))
|
82
|
+
([sample] + sample_additional_files).each do |file|
|
83
|
+
puts
|
84
|
+
puts "# #{file}"
|
85
|
+
puts
|
86
|
+
puts File.read(file)
|
87
|
+
puts
|
88
|
+
puts '# # #'
|
89
|
+
puts
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
task :requires do
|
94
|
+
require 'text-table'
|
95
|
+
require 'facets/string/titlecase'
|
96
|
+
require 'facets/string/underscore'
|
97
|
+
|
98
|
+
require_relative 'launcher'
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
6
103
|
namespace :package do
|
7
104
|
desc 'Clean by removing "dist" and "packages" directories'
|
8
105
|
task :clean do
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require_relative "contact_manager/contact_manager_presenter"
|
2
|
+
|
3
|
+
class ContactManager
|
4
|
+
include Glimmer
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@contact_manager_presenter = ContactManagerPresenter.new
|
8
|
+
@contact_manager_presenter.list
|
9
|
+
end
|
10
|
+
|
11
|
+
def launch
|
12
|
+
shell {
|
13
|
+
text "Contact Manager"
|
14
|
+
composite {
|
15
|
+
group {
|
16
|
+
grid_layout(2, false) {
|
17
|
+
margin_width 0
|
18
|
+
margin_height 0
|
19
|
+
}
|
20
|
+
layout_data :fill, :center, true, false
|
21
|
+
text 'Lookup Contacts'
|
22
|
+
font height: 24
|
23
|
+
|
24
|
+
label {
|
25
|
+
layout_data :right, :center, false, false
|
26
|
+
text "First &Name: "
|
27
|
+
font height: 16
|
28
|
+
}
|
29
|
+
text {
|
30
|
+
layout_data :fill, :center, true, false
|
31
|
+
text bind(@contact_manager_presenter, :first_name)
|
32
|
+
on_key_pressed {|key_event|
|
33
|
+
@contact_manager_presenter.find if key_event.keyCode == swt(:cr)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
label {
|
38
|
+
layout_data :right, :center, false, false
|
39
|
+
text "&Last Name: "
|
40
|
+
font height: 16
|
41
|
+
}
|
42
|
+
text {
|
43
|
+
layout_data :fill, :center, true, false
|
44
|
+
text bind(@contact_manager_presenter, :last_name)
|
45
|
+
on_key_pressed {|key_event|
|
46
|
+
@contact_manager_presenter.find if key_event.keyCode == swt(:cr)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
label {
|
51
|
+
layout_data :right, :center, false, false
|
52
|
+
text "&Email: "
|
53
|
+
font height: 16
|
54
|
+
}
|
55
|
+
text {
|
56
|
+
layout_data :fill, :center, true, false
|
57
|
+
text bind(@contact_manager_presenter, :email)
|
58
|
+
on_key_pressed {|key_event|
|
59
|
+
@contact_manager_presenter.find if key_event.keyCode == swt(:cr)
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
composite {
|
64
|
+
row_layout {
|
65
|
+
margin_width 0
|
66
|
+
margin_height 0
|
67
|
+
}
|
68
|
+
layout_data(:right, :center, false, false) {
|
69
|
+
horizontal_span 2
|
70
|
+
}
|
71
|
+
|
72
|
+
button {
|
73
|
+
text "&Find"
|
74
|
+
on_widget_selected { @contact_manager_presenter.find }
|
75
|
+
on_key_pressed {|key_event|
|
76
|
+
@contact_manager_presenter.find if key_event.keyCode == swt(:cr)
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
button {
|
81
|
+
text "&List All"
|
82
|
+
on_widget_selected { @contact_manager_presenter.list }
|
83
|
+
on_key_pressed {|key_event|
|
84
|
+
@contact_manager_presenter.list if key_event.keyCode == swt(:cr)
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
table(:multi) { |table_proxy|
|
91
|
+
layout_data {
|
92
|
+
horizontal_alignment :fill
|
93
|
+
vertical_alignment :fill
|
94
|
+
grab_excess_horizontal_space true
|
95
|
+
grab_excess_vertical_space true
|
96
|
+
height_hint 200
|
97
|
+
}
|
98
|
+
table_column {
|
99
|
+
text "First Name"
|
100
|
+
width 80
|
101
|
+
}
|
102
|
+
table_column {
|
103
|
+
text "Last Name"
|
104
|
+
width 80
|
105
|
+
}
|
106
|
+
table_column {
|
107
|
+
text "Email"
|
108
|
+
width 200
|
109
|
+
}
|
110
|
+
items bind(@contact_manager_presenter, :results),
|
111
|
+
column_properties(:first_name, :last_name, :email)
|
112
|
+
on_mouse_up { |event|
|
113
|
+
table_proxy.edit_table_item(event.table_item, event.column_index)
|
114
|
+
}
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}.open
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
ContactManager.new.launch
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "contact_repository"
|
2
|
+
|
3
|
+
class ContactManager
|
4
|
+
class ContactManagerPresenter
|
5
|
+
attr_accessor :results
|
6
|
+
@@contact_attributes = [:first_name, :last_name, :email]
|
7
|
+
@@contact_attributes.each {|attribute_name| attr_accessor attribute_name}
|
8
|
+
|
9
|
+
def initialize(contact_repository = nil)
|
10
|
+
@contact_repository = contact_repository || ContactRepository.new
|
11
|
+
@results = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def list
|
15
|
+
self.results = @contact_repository.find({})
|
16
|
+
end
|
17
|
+
|
18
|
+
def find
|
19
|
+
filter_map = {}
|
20
|
+
@@contact_attributes.each do |attribute_name|
|
21
|
+
filter_map[attribute_name] = self.send(attribute_name) if self.send(attribute_name)
|
22
|
+
end
|
23
|
+
self.results = @contact_repository.find(filter_map)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
require_relative "contact"
|
2
|
+
|
3
|
+
class ContactManager
|
4
|
+
class ContactRepository
|
5
|
+
NAMES_FIRST = %w[
|
6
|
+
Liam
|
7
|
+
Noah
|
8
|
+
William
|
9
|
+
James
|
10
|
+
Oliver
|
11
|
+
Benjamin
|
12
|
+
Elijah
|
13
|
+
Lucas
|
14
|
+
Mason
|
15
|
+
Logan
|
16
|
+
Alexander
|
17
|
+
Ethan
|
18
|
+
Jacob
|
19
|
+
Michael
|
20
|
+
Daniel
|
21
|
+
Henry
|
22
|
+
Jackson
|
23
|
+
Sebastian
|
24
|
+
Aiden
|
25
|
+
Matthew
|
26
|
+
Samuel
|
27
|
+
David
|
28
|
+
Joseph
|
29
|
+
Carter
|
30
|
+
Owen
|
31
|
+
Wyatt
|
32
|
+
John
|
33
|
+
Jack
|
34
|
+
Luke
|
35
|
+
Jayden
|
36
|
+
Dylan
|
37
|
+
Grayson
|
38
|
+
Levi
|
39
|
+
Isaac
|
40
|
+
Gabriel
|
41
|
+
Julian
|
42
|
+
Mateo
|
43
|
+
Anthony
|
44
|
+
Jaxon
|
45
|
+
Lincoln
|
46
|
+
Joshua
|
47
|
+
Christopher
|
48
|
+
Andrew
|
49
|
+
Theodore
|
50
|
+
Caleb
|
51
|
+
Ryan
|
52
|
+
Asher
|
53
|
+
Nathan
|
54
|
+
Thomas
|
55
|
+
Leo
|
56
|
+
Isaiah
|
57
|
+
Charles
|
58
|
+
Josiah
|
59
|
+
Hudson
|
60
|
+
Christian
|
61
|
+
Hunter
|
62
|
+
Connor
|
63
|
+
Eli
|
64
|
+
Ezra
|
65
|
+
Aaron
|
66
|
+
Landon
|
67
|
+
Adrian
|
68
|
+
Jonathan
|
69
|
+
Nolan
|
70
|
+
Jeremiah
|
71
|
+
Easton
|
72
|
+
Elias
|
73
|
+
Colton
|
74
|
+
Cameron
|
75
|
+
Carson
|
76
|
+
Robert
|
77
|
+
Angel
|
78
|
+
Maverick
|
79
|
+
Nicholas
|
80
|
+
Dominic
|
81
|
+
Jaxson
|
82
|
+
Greyson
|
83
|
+
Adam
|
84
|
+
Ian
|
85
|
+
Austin
|
86
|
+
Santiago
|
87
|
+
Jordan
|
88
|
+
Cooper
|
89
|
+
Brayden
|
90
|
+
Roman
|
91
|
+
Evan
|
92
|
+
Ezekiel
|
93
|
+
Xaviar
|
94
|
+
Jose
|
95
|
+
Jace
|
96
|
+
Jameson
|
97
|
+
Leonardo
|
98
|
+
Axel
|
99
|
+
Everett
|
100
|
+
Kayden
|
101
|
+
Miles
|
102
|
+
Sawyer
|
103
|
+
Jason
|
104
|
+
Emma
|
105
|
+
Olivia
|
106
|
+
Ava
|
107
|
+
Isabella
|
108
|
+
Sophia
|
109
|
+
Charlotte
|
110
|
+
Mia
|
111
|
+
Amelia
|
112
|
+
Harper
|
113
|
+
Evelyn
|
114
|
+
Abigail
|
115
|
+
Emily
|
116
|
+
Elizabeth
|
117
|
+
Mila
|
118
|
+
Ella
|
119
|
+
Avery
|
120
|
+
Sofia
|
121
|
+
Camila
|
122
|
+
Aria
|
123
|
+
Scarlett
|
124
|
+
Victoria
|
125
|
+
Madison
|
126
|
+
Luna
|
127
|
+
Grace
|
128
|
+
Chloe
|
129
|
+
Penelope
|
130
|
+
Layla
|
131
|
+
Riley
|
132
|
+
Zoey
|
133
|
+
Nora
|
134
|
+
Lily
|
135
|
+
Eleanor
|
136
|
+
Hannah
|
137
|
+
Lillian
|
138
|
+
Addison
|
139
|
+
Aubrey
|
140
|
+
Ellie
|
141
|
+
Stella
|
142
|
+
Natalie
|
143
|
+
Zoe
|
144
|
+
Leah
|
145
|
+
Hazel
|
146
|
+
Violet
|
147
|
+
Aurora
|
148
|
+
Savannah
|
149
|
+
Audrey
|
150
|
+
Brooklyn
|
151
|
+
Bella
|
152
|
+
Claire
|
153
|
+
Skylar
|
154
|
+
Lucy
|
155
|
+
Paisley
|
156
|
+
Everly
|
157
|
+
Anna
|
158
|
+
Caroline
|
159
|
+
Nova
|
160
|
+
Genesis
|
161
|
+
Emilia
|
162
|
+
Kennedy
|
163
|
+
Samantha
|
164
|
+
Maya
|
165
|
+
Willow
|
166
|
+
Kinsley
|
167
|
+
Naomi
|
168
|
+
Aaliyah
|
169
|
+
Elena
|
170
|
+
Sarah
|
171
|
+
Ariana
|
172
|
+
Allison
|
173
|
+
Gabriella
|
174
|
+
Alice
|
175
|
+
Madelyn
|
176
|
+
Cora
|
177
|
+
Ruby
|
178
|
+
Eva
|
179
|
+
Serenity
|
180
|
+
Autumn
|
181
|
+
Adeline
|
182
|
+
Hailey
|
183
|
+
Gianna
|
184
|
+
Valentina
|
185
|
+
Isla
|
186
|
+
Eliana
|
187
|
+
Quinn
|
188
|
+
Nevaeh
|
189
|
+
Ivy
|
190
|
+
Sadie
|
191
|
+
Piper
|
192
|
+
Lydia
|
193
|
+
Alexa
|
194
|
+
Josephine
|
195
|
+
Emery
|
196
|
+
Julia
|
197
|
+
Delilah
|
198
|
+
Arianna
|
199
|
+
Vivian
|
200
|
+
Kaylee
|
201
|
+
Sophie
|
202
|
+
Brielle
|
203
|
+
Madeline
|
204
|
+
]
|
205
|
+
NAMES_LAST = %w[
|
206
|
+
Smith
|
207
|
+
Johnson
|
208
|
+
Williams
|
209
|
+
Brown
|
210
|
+
Jones
|
211
|
+
Miller
|
212
|
+
Davis
|
213
|
+
Wilson
|
214
|
+
Anderson
|
215
|
+
Taylor
|
216
|
+
]
|
217
|
+
def initialize(contacts = nil)
|
218
|
+
@contacts = contacts || 1000.times.map do |n|
|
219
|
+
random_first_name_index = (rand*NAMES_FIRST.size).to_i
|
220
|
+
random_last_name_index = (rand*NAMES_LAST.size).to_i
|
221
|
+
first_name = NAMES_FIRST[random_first_name_index]
|
222
|
+
last_name = NAMES_LAST[random_last_name_index]
|
223
|
+
email = "#{first_name}@#{last_name}.com".downcase
|
224
|
+
Contact.new(
|
225
|
+
first_name: first_name,
|
226
|
+
last_name: last_name,
|
227
|
+
email: email
|
228
|
+
)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def find(attribute_filter_map)
|
233
|
+
@contacts.find_all do |contact|
|
234
|
+
match = true
|
235
|
+
attribute_filter_map.keys.each do |attribute_name|
|
236
|
+
contact_value = contact.send(attribute_name).downcase
|
237
|
+
filter_value = attribute_filter_map[attribute_name].downcase
|
238
|
+
match = false unless contact_value.match(filter_value)
|
239
|
+
end
|
240
|
+
match
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|