Class: Keisan::StringAndGroupParser::CommentPortion

Inherits:
Portion
  • Object
show all
Defined in:
lib/keisan/string_and_group_parser.rb

Instance Attribute Summary collapse

Attributes inherited from Portion

#end_index, #start_index

Instance Method Summary collapse

Constructor Details

#initialize(expression, start_index) ⇒ CommentPortion

Returns a new instance of CommentPortion.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/keisan/string_and_group_parser.rb', line 161

def initialize(expression, start_index)
  super(start_index)

  if expression[start_index] != '#'
    raise Keisan::Exceptions::TokenizingError.new("Comment should start with '#'")
  else
    index = start_index + 1
  end

  while index < expression.size
    break if expression[index] == "\n"
    index += 1
  end

  @end_index = index
  @string = expression[start_index...end_index]
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



159
160
161
# File 'lib/keisan/string_and_group_parser.rb', line 159

def string
  @string
end

Instance Method Details

#sizeObject



179
180
181
# File 'lib/keisan/string_and_group_parser.rb', line 179

def size
  string.size
end

#to_sObject



183
184
185
# File 'lib/keisan/string_and_group_parser.rb', line 183

def to_s
  string
end