Class: Generator
- Inherits:
-
Object
show all
- Defined in:
- lib/dunmanifestin/generator.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(lines) ⇒ Generator
Returns a new instance of Generator.
6
7
8
9
10
|
# File 'lib/dunmanifestin/generator.rb', line 6
def initialize lines
lines.inject do |list, line|
create_or_append_list(list, line)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(slug) ⇒ Object
28
29
30
|
# File 'lib/dunmanifestin/generator.rb', line 28
def method_missing slug
generate slug
end
|
Class Method Details
.from_file(path) ⇒ Object
2
3
4
|
# File 'lib/dunmanifestin/generator.rb', line 2
def self.from_file path
new File.open(path).readlines.map(&:chomp).reject { |line| line.empty? }.unshift('root')
end
|
Instance Method Details
#generate(kind) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/dunmanifestin/generator.rb', line 16
def generate kind
kind = kind.to_s
list = lists[kind] || lists['|' + kind]
return "{#{kind}?}" unless list
list.sample.to_s
end
|
#lists ⇒ Object
12
13
14
|
# File 'lib/dunmanifestin/generator.rb', line 12
def lists
@lists ||= {}
end
|
#manifest(phrase) ⇒ Object
23
24
25
26
|
# File 'lib/dunmanifestin/generator.rb', line 23
def manifest phrase
phrase.to_s
end
|