Class: Oktest::Util::PartialRegexp

Inherits:
Regexp
  • Object
show all
Defined in:
lib/oktest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#beginObject

Returns the value of attribute begin.



2363
2364
2365
# File 'lib/oktest.rb', line 2363

def begin
  @begin
end

#endObject

Returns the value of attribute end.



2363
2364
2365
# File 'lib/oktest.rb', line 2363

def end
  @end
end

#markObject

Returns the value of attribute mark.



2363
2364
2365
# File 'lib/oktest.rb', line 2363

def mark
  @mark
end

#pattern_stringObject

Returns the value of attribute pattern_string.



2363
2364
2365
# File 'lib/oktest.rb', line 2363

def pattern_string
  @pattern_string
end

Instance Method Details

#inspectObject



2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
# File 'lib/oktest.rb', line 2364

def inspect()
  #; [!uyh31] returns function call style string if @pattern_string is set.
  if @pattern_string
    c = @pattern_string.end_with?("\n") ? "" : ".chomp"
    p = @pattern_string.chomp
    b = @begin == '\A' ? "'\\A'" : @begin.inspect
    e = @end   == '\z' ? "'\\z'" : @end.inspect
    m = mark == "{== ==}" ? "" : ", #{mark.inspect}"
    return "partial_regexp(<<PREXP#{c}, #{b}, #{e}#{m})\n#{p}\nPREXP\n"
  #; [!ts9v4] returns regexp literal style string if @pattern_string is not set.
  else
    s = super
    s = s.gsub(/([^\\](?:\\\\)*)((?:\\n)+)/) {
      $1 + ("\\n\n" * ($2.length / 2))
    }
    if s =~ /\n/
      s = s.sub(/\A\/(\\A)?/, "/\\1\n")
      s = s + "x"   # `/.../x` means multiline regexp
    end
    return s
  end
end