Class: Keisan::StringAndGroupParser::OtherPortion

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) ⇒ OtherPortion

Returns a new instance of OtherPortion.



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/keisan/string_and_group_parser.rb', line 126

def initialize(expression, start_index)
  super(start_index)

  case expression[start_index]
  when STRING_CHARACTER_REGEX, OPEN_GROUP_REGEX, CLOSED_GROUP_REGEX
    raise Keisan::Exceptions::TokenizingError.new("Internal error, OtherPortion should not have string/braces at start")
  else
    index = start_index + 1
  end

  while index < expression.size
    case expression[index]
    when STRING_CHARACTER_REGEX, OPEN_GROUP_REGEX, CLOSED_GROUP_REGEX, COMMENT_CHARACTER_REGEX
      break
    else
      index += 1
    end
  end

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

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



124
125
126
# File 'lib/keisan/string_and_group_parser.rb', line 124

def string
  @string
end

Instance Method Details

#sizeObject



149
150
151
# File 'lib/keisan/string_and_group_parser.rb', line 149

def size
  string.size
end

#to_sObject



153
154
155
# File 'lib/keisan/string_and_group_parser.rb', line 153

def to_s
  string
end