Module: OLE_QA::Framework::Bib_Factory
- Extended by:
- Factory_Helpers
- Defined in:
- lib/data_factory/bib_factory.rb
Overview
Manufacture strings for bibliographic, instance, and item record testing
Class Method Summary collapse
-
.author(first_len = 4..6, last_len = 8..12) ⇒ Object
Return a random author with specified first and last name lengths.
-
.barcode ⇒ Object
Return a random string of between 12 and 18 numbers to be used as a barcode.
-
.call_number(format = "LOC") ⇒ Object
Return a random (non-validated) call number in the specified format.
-
.circulation_info(desk_code = '') ⇒ Object
Return a hash containing circulation desk and location information.
-
.title(len = 8..12) ⇒ Object
Return a random title with the specified length.
Class Method Details
.author(first_len = 4..6, last_len = 8..12) ⇒ Object
Return a random author with specified first and last name lengths.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/data_factory/bib_factory.rb', line 49 def (first_len = 4..6, last_len = 8..12) str = String.new if first_len.class == Range str << name_builder(sampler(first_len)) else str << name_builder(first_len.to_i) end str << ' ' if last_len.class == Range str << name_builder(sampler(last_len)) else str << name_builder(last_len.to_i) end end |
.barcode ⇒ Object
Return a random string of between 12 and 18 numbers to be used as a barcode.
23 24 25 |
# File 'lib/data_factory/bib_factory.rb', line 23 def (0..(11..17).to_a.sample).map{(0..9).to_a.sample}.join end |
.call_number(format = "LOC") ⇒ Object
Return a random (non-validated) call number in the specified format.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/data_factory/bib_factory.rb', line 28 def call_number(format = "LOC") call_num = Array.new # TODO - Use case...when once other formats are added. # LOC Format Call Number call_num << (0..(0..1).to_a.sample).map{('A'..'Z').to_a.sample}.join call_num << (0..(1..3).to_a.sample).map{(1..9).to_a.sample}.join << " " call_num << "." << ('A'..'Z').to_a.sample call_num << (0..(1..2).to_a.sample).map{(1..9).to_a.sample}.join call_num.join end |
.circulation_info(desk_code = '') ⇒ Object
Pass a circulation desk code defined in data/circulation.yml to return info on a specific circulation desk.
Return a hash containing circulation desk and location information.
67 68 69 70 71 72 |
# File 'lib/data_factory/bib_factory.rb', line 67 def circulation_info(desk_code = '') circ_ary = YAML.load_file(OLE_QA::Framework.data_dir + '/circulation.yml') hsh_out = desk_code.empty? ? circ_ary.sample : circ_ary.find {|circ| circ[:code] == desk_code} raise OLE_QA::Framework::Error,"No circulation desk found.#{ ' Given: ' + desk_code unless desk_code.empty?}" if hsh_out.nil? return hsh_out end |
.title(len = 8..12) ⇒ Object
Return a random title with the specified length.
40 41 42 43 44 45 46 |
# File 'lib/data_factory/bib_factory.rb', line 40 def title(len = 8..12) if len.class == Range name_builder(sampler(len)) else name_builder(len.to_i) end end |