123456789_123456789_123456789_123456789_123456789_

Module: Capybara::Node::WhitespaceNormalizer

Overview

WhitespaceNormalizer provides methods that help to normalize the spacing of text content inside of Elements by removing various unicode spacing and directional markings.

Constant Summary

Instance Method Summary

Instance Method Details

#normalize_spacing(text) ⇒ String

Normalizes the spacing of a node’s text to be similar to what matchers might expect.

Parameters:

  • text (String)
[ GitHub ]

  
# File 'lib/capybara/node/whitespace_normalizer.rb', line 53

def normalize_spacing(text)
  text
    .delete(REMOVED_CHARACTERS)
    .tr(SQUEEZED_SPACES, ' ')
    .squeeze(' ')
    .sub(LEADING_SPACES, '')
    .sub(TRAILING_SPACES, '')
    .tr(NON_BREAKING_SPACE, ' ')
end

#normalize_visible_spacing(text) ⇒ String

Variant on Capybara::Node::Normalizer#normalize_spacing that targets the whitespace of visible elements only.

Parameters:

  • text (String)
[ GitHub ]

  
# File 'lib/capybara/node/whitespace_normalizer.rb', line 71

def normalize_visible_spacing(text)
  text
    .squeeze(' ')
    .gsub(EMPTY_LINES, "\n")
    .sub(LEADING_SPACES, '')
    .sub(TRAILING_SPACES, '')
    .tr(NON_BREAKING_SPACE, ' ')
end