Class: Inform::Verb

Inherits:
Set show all
Defined in:
lib/story_teller/grammar_parser.rb

Overview

Verbs

Defined Under Namespace

Classes: Grammar

Constant Summary collapse

SpaceString =
' '.freeze
VerbString =
'Verb'.freeze
MetaString =
'meta'.freeze
EmoteString =
'emote'.freeze
Newline =
"\n".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Set

#ruby_to_s

Constructor Details

#initialize(verbs, source, meta = nil, emote = nil) ⇒ Verb

Returns a new instance of Verb.



52
53
54
55
56
57
58
59
# File 'lib/story_teller/grammar_parser.rb', line 52

def initialize(verbs, source, meta = nil, emote = nil)
  super()
  merge(verbs)
  @meta = meta unless meta.nil?
  @emote = emote unless emote.nil?
  @grammars = []
  @source = source
end

Instance Attribute Details

#emoteObject (readonly)

Returns the value of attribute emote.



49
50
51
# File 'lib/story_teller/grammar_parser.rb', line 49

def emote
  @emote
end

#grammarsObject

Returns the value of attribute grammars.



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

def grammars
  @grammars
end

#metaObject (readonly)

Returns the value of attribute meta.



49
50
51
# File 'lib/story_teller/grammar_parser.rb', line 49

def meta
  @meta
end

#sourceObject

Returns the value of attribute source.



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

def source
  @source
end

Instance Method Details

#<=>(other) ⇒ Object



66
67
68
69
# File 'lib/story_teller/grammar_parser.rb', line 66

def <=>(other)
  !other.nil? && include?(other.to_s) &&
    meta? == other.meta? && grammars == other.grammars && super
end

#==(other) ⇒ Object



61
62
63
64
# File 'lib/story_teller/grammar_parser.rb', line 61

def ==(other)
  !other.nil? && include?(other.to_s) &&
    meta? == other.meta? && grammars == other.grammars && super
end

#emote?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/story_teller/grammar_parser.rb', line 84

def emote?
  !emote.nil?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/story_teller/grammar_parser.rb', line 71

def eql?(other)
  !other.nil? && include?(other.to_s) &&
    meta? == other.meta? && grammars == other.grammars && super
end

#hashObject



115
116
117
# File 'lib/story_teller/grammar_parser.rb', line 115

def hash
  [super, meta, emote, grammars].hash
end

#meta?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/story_teller/grammar_parser.rb', line 80

def meta?
  !meta.nil?
end

#to_sObject Also known as: to_str

rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/story_teller/grammar_parser.rb', line 96

def to_s
  grammar_lines = grammars.map(&:to_s)
  grammar_lines[-1] = "#{grammar_lines[-1]};" if grammar_lines.any?

  VerbString + SpaceString +
    if meta?
      MetaString + SpaceString
    elsif emote?
      EmoteString + SpaceString
    else
      ''
    end +
    map { |verb| "'#{verb}'" }.join(SpaceString) + Newline +
    grammar_lines.join(Newline)
end

#verbObject



76
77
78
# File 'lib/story_teller/grammar_parser.rb', line 76

def verb
  first
end