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
# File 'lib/meetup_generator.rb', line 14

def initialize
  @words = Zlib::GzipReader.open(LIB + 'words.gz').readlines.map(&:strip)
  @lib   = YAML.load_file(LIB + 'all_the_things.yaml')
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



22
23
24
25
26
27
# File 'lib/meetup_generator.rb', line 22

def agenda(num = 5)
  { talks: lib[:template].sample(num).map { |t| talk(t) },
    refreshment: refreshment,
    location: location,
    date: date }
end

#companyObject



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

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

#dateObject



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

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

#locationObject



38
39
40
# File 'lib/meetup_generator.rb', line 38

def location
  'Shoreditch, probably'
end

#pair(list1, list2) ⇒ Object



74
75
76
# File 'lib/meetup_generator.rb', line 74

def pair(list1, list2)
  [lib[list1].sample, lib[list2].sample].join(' ')
end

#random_template(number = 1) ⇒ Object



50
51
52
# File 'lib/meetup_generator.rb', line 50

def random_template(number = 1)
  lib[:template].sample(number).first
end

#refreshmentObject



62
63
64
# File 'lib/meetup_generator.rb', line 62

def refreshment
  pair(:food_style, :food)
end

#replace_number(template) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/meetup_generator.rb', line 98

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



92
93
94
95
96
# File 'lib/meetup_generator.rb', line 92

def replace_ops(template)
  return template unless template.include?('%FNOPS%')

  replace_ops(template.sub('%FNOPS%', something_ops))
end

#replace_things(template) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/meetup_generator.rb', line 78

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



86
87
88
89
90
# File 'lib/meetup_generator.rb', line 86

def replace_word(template)
  return template unless template.include?('%WORD%')

  replace_word(template.sub('%WORD%', words.sample.capitalize))
end

#roleObject



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

def role
  pair(:job_role, :job_title)
end

#something_opsObject



70
71
72
# File 'lib/meetup_generator.rb', line 70

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



31
32
33
34
35
36
# File 'lib/meetup_generator.rb', line 31

def talk(template = random_template)
  { title: title(template),
    talker: talker,
    role: role,
    company: company }
end

#talkerObject



54
55
56
# File 'lib/meetup_generator.rb', line 54

def talker
  pair(:first_name, :last_name)
end

#title(template = random_template) ⇒ Object



46
47
48
# File 'lib/meetup_generator.rb', line 46

def title(template = random_template)
  replace_word(replace_number(replace_ops(replace_things(template))))
end