Class: Balm::Plot

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

Overview

this class will generate aspects of a story: trope, archetype and setting

Class Method Summary collapse

Class Method Details

.all(num, type = "list") ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/balm.rb', line 47

def all(num, type = "list")
  if type === "prompt"
    if trope.downcase.end_with?("!")
      if setting.downcase.start_with?(/[io]+/)
        puts "Once upon a time, a #{archetype(num)} are #{setting.downcase} and #{trope.downcase} Have you found your path?"
      else
        puts "Once upon a time, a #{archetype(num)} are in #{setting.downcase} and #{trope.downcase} Have you found your path?"
      end
    else
      if setting.downcase.start_with?(/[io]+/)
        puts "Once upon a time, a #{archetype(num)} are #{setting.downcase} and #{trope.downcase}. Have you found your path?"
      elsif setting.downcase.start_with?("as")
        puts "Once upon a time, a #{archetype(num)} #{setting.downcase} and #{trope.downcase}. Have you found your path?"
      else
        puts "Once upon a time, a #{archetype(num)} are in #{setting.downcase} and #{trope.downcase}. Have you found your path?"
      end
    end
  else
    prompt_list = { trope: trope, archetypes: archetype(num), setting: setting }
    puts prompt_list
  end
end

.archetype(num) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/balm.rb', line 21

def archetype(num)
  archetypes = []
  archetype_data = File.join(File.dirname(__FILE__), "archetypes.yaml")
  YAML.load_file(archetype_data).each do |archetype|
    archetypes << archetype.strip
  end
  if num === 1
    archetypes.sample(num)
  elsif num === 2
    archetypes.sample(num).join(" and ")
  elsif num >= 3
    archetypes_list = archetypes.sample(num)
    archetypes_list[-1] = "and " + archetypes_list[-1] 
    archetypes_list.join(", ")
  end
end

.settingObject



38
39
40
41
42
43
44
45
# File 'lib/balm.rb', line 38

def setting
  setting_data = File.join(File.dirname(__FILE__), "settings.yaml")
  settings = []
  YAML.load_file(setting_data).each do |setting|
    settings << setting.strip
  end
  settings.sample
end

.tropeObject



12
13
14
15
16
17
18
19
# File 'lib/balm.rb', line 12

def trope
  trope_data = File.join(File.dirname(__FILE__), "tropes.yaml")
  tropes = []
  YAML.load_file(trope_data).each do |trope|
    tropes << trope.strip
  end
  tropes.sample
end