Class: MeetupGenerator
- Inherits:
-
Object
- Object
- MeetupGenerator
- Defined in:
- lib/meetup_generator.rb
Overview
Everything needed for a meetup generator
Instance Attribute Summary collapse
-
#lib ⇒ Object
readonly
Returns the value of attribute lib.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Instance Method Summary collapse
-
#agenda(num = 5) ⇒ Hash
Full meetup agenda.
- #company ⇒ Object
- #date ⇒ Object
-
#initialize ⇒ MeetupGenerator
constructor
A new instance of MeetupGenerator.
- #location ⇒ Object
- #pair(list1, list2) ⇒ Object
- #random_template(number = 1) ⇒ Object
- #refreshment ⇒ Object
- #replace_number(template) ⇒ Object
- #replace_ops(template) ⇒ Object
- #replace_things(template) ⇒ Object
- #replace_word(template) ⇒ Object
- #role ⇒ Object
- #something_ops ⇒ Object
- #talk(template = random_template) ⇒ Object
- #talker ⇒ Object
- #title(template = random_template) ⇒ Object
Constructor Details
#initialize ⇒ MeetupGenerator
Returns a new instance of MeetupGenerator.
14 15 16 17 18 |
# File 'lib/meetup_generator.rb', line 14 def initialize @words = Zlib::GzipReader.open(LIB + 'words.gz').readlines.map(&:strip) @lib = YAML.safe_load(IO.read(LIB + 'all_the_things.yaml'), symbolize_names: true) end |
Instance Attribute Details
#lib ⇒ Object (readonly)
Returns the value of attribute lib.
12 13 14 |
# File 'lib/meetup_generator.rb', line 12 def lib @lib end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
12 13 14 |
# File 'lib/meetup_generator.rb', line 12 def words @words end |
Instance Method Details
#agenda(num = 5) ⇒ Hash
Returns full meetup agenda.
23 24 25 26 27 28 |
# File 'lib/meetup_generator.rb', line 23 def agenda(num = 5) { talks: lib[:template].sample(num).map { |t| talk(t) }, refreshment: refreshment, location: location, date: date } end |
#company ⇒ Object
67 68 69 |
# File 'lib/meetup_generator.rb', line 67 def company format('%<word>s.io', word: words.sample.sub(/([^aeiou])er$/, '\\1r')) end |
#date ⇒ Object
43 44 45 |
# File 'lib/meetup_generator.rb', line 43 def date (Date.today + 1).strftime('%d/%m/%Y') end |
#location ⇒ Object
39 40 41 |
# File 'lib/meetup_generator.rb', line 39 def location 'Shoreditch, probably' end |
#pair(list1, list2) ⇒ Object
75 76 77 |
# File 'lib/meetup_generator.rb', line 75 def pair(list1, list2) [lib[list1].sample, lib[list2].sample].join(' ') end |
#random_template(number = 1) ⇒ Object
51 52 53 |
# File 'lib/meetup_generator.rb', line 51 def random_template(number = 1) lib[:template].sample(number).first end |
#refreshment ⇒ Object
63 64 65 |
# File 'lib/meetup_generator.rb', line 63 def refreshment pair(:food_style, :food) end |
#replace_number(template) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/meetup_generator.rb', line 99 def replace_number(template) return template unless template =~ /%RAND\d+%/ replace_number(template.sub(/%RAND(\d+)%/) do rand(2..Regexp.last_match(1).to_i).to_s end) end |
#replace_ops(template) ⇒ Object
93 94 95 96 97 |
# File 'lib/meetup_generator.rb', line 93 def replace_ops(template) return template unless template.include?('%FNOPS%') replace_ops(template.sub('%FNOPS%', something_ops)) end |
#replace_things(template) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/meetup_generator.rb', line 79 def replace_things(template) return template unless template =~ /%[a-z_]+%/ replace_things(template.sub(/%([a-z_]+)%/) do lib[Regexp.last_match(1).to_sym].sample end) end |
#replace_word(template) ⇒ Object
87 88 89 90 91 |
# File 'lib/meetup_generator.rb', line 87 def replace_word(template) return template unless template.include?('%WORD%') replace_word(template.sub('%WORD%', words.sample.capitalize)) end |
#role ⇒ Object
59 60 61 |
# File 'lib/meetup_generator.rb', line 59 def role pair(:job_role, :job_title) end |
#something_ops ⇒ Object
71 72 73 |
# File 'lib/meetup_generator.rb', line 71 def something_ops (lib[:something_ops] * 4).sample(rand(2..4)).join + 'Ops' end |
#talk(template = random_template) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/meetup_generator.rb', line 32 def talk(template = random_template) { title: title(template), talker: talker, role: role, company: company } end |
#talker ⇒ Object
55 56 57 |
# File 'lib/meetup_generator.rb', line 55 def talker pair(:first_name, :last_name) end |
#title(template = random_template) ⇒ Object
47 48 49 |
# File 'lib/meetup_generator.rb', line 47 def title(template = random_template) replace_word(replace_number(replace_ops(replace_things(template)))) end |