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.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/keisan/string_and_group_parser.rb', line 120

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
      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.



118
119
120
# File 'lib/keisan/string_and_group_parser.rb', line 118

def string
  @string
end

Instance Method Details

#sizeObject



143
144
145
# File 'lib/keisan/string_and_group_parser.rb', line 143

def size
  string.size
end

#to_sObject



147
148
149
# File 'lib/keisan/string_and_group_parser.rb', line 147

def to_s
  string
end