module WpUser::Existable

Public Class Methods

display_name_from_body(body) click to toggle source

@note Some bodies are encoded in ASCII-8BIT, and Nokogiri doesn’t support it

So it's forced to UTF-8 when this encoding is detected

@param [ String ] body

@return [ String ] The display_name

# File lib/common/models/wp_user/existable.rb, line 63
def self.display_name_from_body(body)
  if title_tag = body[%r{<title>([^<]+)</title>}, 1]
    title_tag.force_encoding('UTF-8') if title_tag.encoding == Encoding::ASCII_8BIT
    title_tag = Nokogiri::HTML::DocumentFragment.parse(title_tag).to_s
    # &amp; are not decoded with Nokogiri

    title_tag.sub!('&amp;', '&')

    name = title_tag[%r{([^|«]+) }, 1]

    return name.strip if name
  end
end
login_from_author_pattern(text) click to toggle source

@param [ String ] text

@return [ String ] The login

# File lib/common/models/wp_user/existable.rb, line 38
def self.login_from_author_pattern(text)
  text[%r{/author/([^/\b]+)/?}, 1]
end
login_from_body(body) click to toggle source

@param [ String ] body

@return [ String ] The login

# File lib/common/models/wp_user/existable.rb, line 45
def self.login_from_body(body)
  # Feed URL with Permalinks

  login = WpUser::Existable.login_from_author_pattern(body)

  unless login
    # No Permalinks

    login = body[%r{<body class="archive author author-([^\s]+) author-(\d+)}, 1]
  end

  login
end

Public Instance Methods

exists_from_response?(response, options = {}) click to toggle source

@param [ Typhoeus::Response ] response @param [ Hash ] options

@return [ Boolean ]

# File lib/common/models/wp_user/existable.rb, line 9
def exists_from_response?(response, options = {})
  load_from_response(response)

  @login ? true : false
end