Class: Playwright::EscapeWithQuotes

Inherits:
Object
  • Object
show all
Defined in:
lib/playwright/locator_impl.rb

Instance Method Summary collapse

Constructor Details

#initialize(text, char = "'") ⇒ EscapeWithQuotes

Returns a new instance of EscapeWithQuotes.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/playwright/locator_impl.rb', line 5

def initialize(text, char = "'")
  stringified = text.to_json
  escaped_text = stringified[1...-1].gsub(/\\"/, '"')

  case char
  when '"'
    text = escaped_text.gsub(/["]/, '\\"')
    @text = "\"#{text}\""
  when "'"
    text = escaped_text.gsub(/[']/, '\\\'')
    @text = "'#{text}'"
  else
    raise ArgumentError.new('Invalid escape char')
  end
end

Instance Method Details

#to_sObject



21
22
23
# File 'lib/playwright/locator_impl.rb', line 21

def to_s
  @text
end