Class: OLE_QA::Framework::Patron_Factory
- Inherits:
-
Object
- Object
- OLE_QA::Framework::Patron_Factory
- Defined in:
- lib/data_factory/patron_factory.rb
Overview
Return usable patron records from source files in ole-qa-framework/data/patron.yml
Class Attribute Summary collapse
-
.borrower_types ⇒ Object
readonly
An array containing a collection of valid borrower types to use for patron records.
-
.patron_matrix ⇒ Object
readonly
An array containing a collection of valid OLE patron records.
-
.states ⇒ Object
readonly
An array containing a collection of valid states to use for patron records.
Class Method Summary collapse
- .name_builder(max_len = 8) ⇒ Object
- .new_patron ⇒ Object
- .num_str(len = 8) ⇒ Object
- .sampler(r = 'A'..'Z') ⇒ Object
-
.select_patron ⇒ Object
Return a random patron record.
- .str(len = 8) ⇒ Object
Class Attribute Details
.borrower_types ⇒ Object (readonly)
An array containing a collection of valid borrower types to use for patron records.
31 32 33 |
# File 'lib/data_factory/patron_factory.rb', line 31 def borrower_types @borrower_types end |
.patron_matrix ⇒ Object (readonly)
An array containing a collection of valid OLE patron records.
25 26 27 |
# File 'lib/data_factory/patron_factory.rb', line 25 def patron_matrix @patron_matrix end |
.states ⇒ Object (readonly)
An array containing a collection of valid states to use for patron records.
28 29 30 |
# File 'lib/data_factory/patron_factory.rb', line 28 def states @states end |
Class Method Details
.name_builder(max_len = 8) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/data_factory/patron_factory.rb', line 53 def name_builder(max_len = 8) out = Array.new out << sampler max_len -= 1 max_len.times do out << sampler('a'..'z') end out.join end |
.new_patron ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/data_factory/patron_factory.rb', line 38 def new_patron patron = Hash.new patron[:first] = name_builder(sampler(2..8)) patron[:last] = name_builder(sampler(6..8)) patron[:barcode] = num_str(sampler(6..12)) patron[:borrower_type] = @borrower_types.sample patron[:address] = num_str(sampler(3..5)) + ' ' + name_builder(sampler(4..8)) + ' ' + name_builder(2) patron[:city] = name_builder(sampler(4..12)) patron[:state] = @states.sample.upcase patron[:postal_code] = num_str(5) patron[:phone] = num_str(3) + '-' + num_str(3) + '-' + num_str(4) patron[:email] = patron[:first] + patron[:last] + '@' + str(sampler(4..8)) + '.' + str(3) patron end |
.num_str(len = 8) ⇒ Object
76 77 78 79 80 |
# File 'lib/data_factory/patron_factory.rb', line 76 def num_str(len = 8) ary = Array.new len.times { ary << sampler('0'..'9') } ary.join end |
.sampler(r = 'A'..'Z') ⇒ Object
64 65 66 |
# File 'lib/data_factory/patron_factory.rb', line 64 def sampler(r = 'A'..'Z') r.to_a.sample end |
.select_patron ⇒ Object
Return a random patron record.
34 35 36 |
# File 'lib/data_factory/patron_factory.rb', line 34 def select_patron @patron_matrix.sample end |
.str(len = 8) ⇒ Object
69 70 71 72 73 |
# File 'lib/data_factory/patron_factory.rb', line 69 def str(len=8) ary = Array.new len.times { ary << sampler('a'..'z') } ary.join end |