Class: MeetupGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/meetup_generator.rb

Overview

Everything needed for a meetup generator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMeetupGenerator

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

#libObject (readonly)

Returns the value of attribute lib.



12
13
14
# File 'lib/meetup_generator.rb', line 12

def lib
  @lib
end

#wordsObject (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.

Parameters:

  • num (Integer) (defaults to: 5)

    how many talks you want

Returns:

  • (Hash)

    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

#companyObject



67
68
69
# File 'lib/meetup_generator.rb', line 67

def company
  format('%<word>s.io', word: words.sample.sub(/([^aeiou])er$/, '\\1r'))
end

#dateObject



43
44
45
# File 'lib/meetup_generator.rb', line 43

def date
  (Date.today + 1).strftime('%d/%m/%Y')
end

#locationObject



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

#refreshmentObject



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

#roleObject



59
60
61
# File 'lib/meetup_generator.rb', line 59

def role
  pair(:job_role, :job_title)
end

#something_opsObject



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

Parameters:

  • templates (Array[String])

    array of templates



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

#talkerObject



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