class Regextest::Front::Sequence::Sequence
Attributes
elements[R]
length[R]
offset[R]
Public Class Methods
new(elem)
click to toggle source
Constructor
# File lib/regextest/front/sequence.rb, line 15 def initialize(elem) TstLog("Sequence: #{elem}") @offset = elem.offset @length = elem.length @elements = [elem] end
Public Instance Methods
add(elem)
click to toggle source
add an element (a letter or a parenthesis) to sequence
# File lib/regextest/front/sequence.rb, line 25 def add(elem) TstLog("Sequence add: #{elem}") @elements.push elem @length += elem.length self end
concatinate(other_obj)
click to toggle source
concatinate other sequence object to sequence
# File lib/regextest/front/sequence.rb, line 33 def concatinate(other_obj) TstLog("Sequence concatinate: #{other_obj}") @elements += other_obj.elements @length += other_obj.length self end
json()
click to toggle source
transform to json format
# File lib/regextest/front/sequence.rb, line 56 def json # if @elements.size > 1 @@id += 1 "{\"type\": \"LEX_SEQ\", " + " \"id\": \"q#{@@id}\", " + " \"offset\": \"#{@offset}\", " + " \"length\": \"#{@length}\", " + " \"value\": [#{@elements.map{|elem| elem.json}.join(",")}]}" # else # @elements[0].json #end end
set_options(options)
click to toggle source
set options
# File lib/regextest/front/sequence.rb, line 41 def set_options(options) TstLog("Sequence set_options: #{options[:reg_options].inspect}") # dup for preventing from rewrite in the sequence new_options = options.dup new_options[:reg_options] = options[:reg_options].dup # call elements of the sequence @elements.each do | element | element.set_options(new_options) end self end