Class: Imasgen::GeneratorBase
- Inherits:
-
Object
- Object
- Imasgen::GeneratorBase
show all
- Defined in:
- lib/imasgen/generator_base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of GeneratorBase.
8
9
10
11
12
13
|
# File 'lib/imasgen/generator_base.rb', line 8
def initialize
@namedic = []
@used_pair = []
@auto_reset = false
@be_strict = true
end
|
Instance Attribute Details
#auto_reset ⇒ Object
Returns the value of attribute auto_reset.
5
6
7
|
# File 'lib/imasgen/generator_base.rb', line 5
def auto_reset
@auto_reset
end
|
#be_strict ⇒ Object
Returns the value of attribute be_strict.
6
7
8
|
# File 'lib/imasgen/generator_base.rb', line 6
def be_strict
@be_strict
end
|
Class Method Details
.getyaml ⇒ Object
72
73
74
|
# File 'lib/imasgen/generator_base.rb', line 72
def self.getyaml
throw NotImplementedError
end
|
Instance Method Details
#hotchpotch ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/imasgen/generator_base.rb', line 49
def hotchpotch
item = lambda {
@basedic ||= @be_strict ? @namedic.select {|i| i[:last_name] != '' && i[:first_name] != ''} : @namedic
@first_names ||= @basedic.map {|i| {first_name: i[:first_name], first_name_furigana: i[:first_name_furigana]}}
@last_names ||= @basedic.map {|i| {last_name: i[:last_name], last_name_furigana: i[:last_name_furigana]}}
@comb ||= @first_names.product(@last_names).map {|i| i[0].merge(i[1])}
ret = @comb.reject {|i| i[:used]}.sample
return ret unless ret.nil?
if @auto_reset
@comb.each {|i| i.delete(:used)}
ret
else
raise StandardError.new('Already used all name pairs.')
end
}.call
item[:used] = true
Imasgen::Name.new(item)
end
|
#name ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/imasgen/generator_base.rb', line 32
def name
item = lambda {
@basedic ||= @be_strict ? @namedic.select {|i| i[:last_name] != '' && i[:first_name] != ''} : @namedic
retval = @basedic.reject {|i| i[:used]}.sample
raise StandardError.new('Already used all name pairs.') if retval.nil? && !@auto_reset
if retval.nil? && @auto_reset
@basedic.each {|i| i.delete(:used)}
retval = @namedic.sample
end
retval
}.call
item[:used] = true
Imasgen::Name.new(item)
end
|
#reset ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/imasgen/generator_base.rb', line 19
def reset
@basedic = nil
@first_names = nil
@last_names = nil
@comb = nil
end
|
#unique ⇒ Object
15
16
17
|
# File 'lib/imasgen/generator_base.rb', line 15
def unique
@unique_i ||= self.class.new
end
|