Class: Gamefic::Active::Epic

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/gamefic/active/epic.rb

Overview

A collection of narratives.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

logger

Constructor Details

#initializeEpic

Returns a new instance of Epic.



13
14
15
# File 'lib/gamefic/active/epic.rb', line 13

def initialize
  @narratives = Set.new
end

Instance Attribute Details

#narrativesSet<Narrative> (readonly)

Returns:



11
12
13
# File 'lib/gamefic/active/epic.rb', line 11

def narratives
  @narratives
end

Instance Method Details

#add(narrative) ⇒ Object

Parameters:



18
19
20
# File 'lib/gamefic/active/epic.rb', line 18

def add narrative
  narratives.add narrative
end

#delete(narrative) ⇒ Object

Parameters:



23
24
25
# File 'lib/gamefic/active/epic.rb', line 23

def delete narrative
  narratives.delete narrative
end

#empty?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/gamefic/active/epic.rb', line 42

def empty?
  narratives.empty?
end

#one?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/gamefic/active/epic.rb', line 46

def one?
  narratives.one?
end

#responses_for(*verbs) ⇒ Array<Response>

Returns:



55
56
57
58
59
# File 'lib/gamefic/active/epic.rb', line 55

def responses_for(*verbs)
  rulebooks.to_a
           .reverse
           .flat_map { |rb| rb.responses_for(*verbs) }
end

#rulebooksArray<Rulebook>

Returns:



28
29
30
# File 'lib/gamefic/active/epic.rb', line 28

def rulebooks
  narratives.map(&:rulebook)
end

#select_scene(name) ⇒ Scene

Parameters:

  • name (Symbol)

Returns:

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
71
# File 'lib/gamefic/active/epic.rb', line 63

def select_scene name
  scenes = rulebooks.map { |rlbk| rlbk.scenes[name] }
                    .compact
  raise ArgumentError, "Scene named `#{name}` does not exist" if scenes.empty?

  logger.warn "Found #{scenes.length} scenes named `#{name}`" unless scenes.one?

  scenes.last
end

#synonymsArray<Symbol>

Returns:



38
39
40
# File 'lib/gamefic/active/epic.rb', line 38

def synonyms
  rulebooks.flat_map(&:synonyms).uniq
end

#syntaxesObject



50
51
52
# File 'lib/gamefic/active/epic.rb', line 50

def syntaxes
  rulebooks.flat_map(&:syntaxes)
end

#verbsArray<Symbol>

Returns:



33
34
35
# File 'lib/gamefic/active/epic.rb', line 33

def verbs
  rulebooks.flat_map(&:verbs).uniq
end