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.



2269
2270
2271
# File 'lib/oktest.rb', line 2269

def begin
  @begin
end

#endObject

Returns the value of attribute end.



2269
2270
2271
# File 'lib/oktest.rb', line 2269

def end
  @end
end

#markObject

Returns the value of attribute mark.



2269
2270
2271
# File 'lib/oktest.rb', line 2269

def mark
  @mark
end

#pattern_stringObject

Returns the value of attribute pattern_string.



2269
2270
2271
# File 'lib/oktest.rb', line 2269

def pattern_string
  @pattern_string
end

Instance Method Details

#inspectObject



2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
# File 'lib/oktest.rb', line 2270

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