Class: Napybara::Selector

Inherits:
Struct
  • Object
show all
Defined in:
lib/napybara/selector.rb

Constant Summary collapse

METHOD_NAME_REGEX =
/\{(\w+)\}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#child_element_selectorObject

Returns the value of attribute child_element_selector

Returns:

  • (Object)

    the current value of child_element_selector



2
3
4
# File 'lib/napybara/selector.rb', line 2

def child_element_selector
  @child_element_selector
end

#recordObject

Returns the value of attribute record

Returns:

  • (Object)

    the current value of record



2
3
4
# File 'lib/napybara/selector.rb', line 2

def record
  @record
end

#record_selectorObject

Returns the value of attribute record_selector

Returns:

  • (Object)

    the current value of record_selector



2
3
4
# File 'lib/napybara/selector.rb', line 2

def record_selector
  @record_selector
end

Instance Method Details

#method_nameObject



4
5
6
# File 'lib/napybara/selector.rb', line 4

def method_name
  record_selector.match(METHOD_NAME_REGEX)[1]
end

#record_idObject



8
9
10
# File 'lib/napybara/selector.rb', line 8

def record_id
  record && record.public_send(method_name)
end

#to_sObject



12
13
14
15
16
17
18
# File 'lib/napybara/selector.rb', line 12

def to_s
  if record
    record_selector.gsub(METHOD_NAME_REGEX, record_id.to_s)
  else
    child_element_selector
  end
end