Class: Inform::Verb

Inherits:
Set show all
Defined in:
lib/runtime/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.



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

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.



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

def emote
  @emote
end

#grammarsObject

Returns the value of attribute grammars.



51
52
53
# File 'lib/runtime/grammar_parser.rb', line 51

def grammars
  @grammars
end

#metaObject (readonly)

Returns the value of attribute meta.



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

def meta
  @meta
end

#sourceObject

Returns the value of attribute source.



51
52
53
# File 'lib/runtime/grammar_parser.rb', line 51

def source
  @source
end

Instance Method Details

#<=>(other) ⇒ Object



67
68
69
70
# File 'lib/runtime/grammar_parser.rb', line 67

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

#==(other) ⇒ Object



62
63
64
65
# File 'lib/runtime/grammar_parser.rb', line 62

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

#emote?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/runtime/grammar_parser.rb', line 85

def emote?
  !emote.nil?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# File 'lib/runtime/grammar_parser.rb', line 72

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

#hashObject



109
110
111
# File 'lib/runtime/grammar_parser.rb', line 109

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

#meta?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/runtime/grammar_parser.rb', line 81

def meta?
  !meta.nil?
end

#to_sObject Also known as: to_str



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/runtime/grammar_parser.rb', line 95

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

#verbObject



77
78
79
# File 'lib/runtime/grammar_parser.rb', line 77

def verb
  first
end