Module: WpUser::Existable

Included in:
WpUser
Defined in:
lib/common/models/wp_user/existable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.display_name_from_body(body) ⇒ String

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

Returns The display_name

Parameters:

  • body (String)

Returns:

  • (String)

    The display_name


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/common/models/wp_user/existable.rb', line 66

def self.display_name_from_body(body)
  if title_tag = body[%r{<title>([^<]+)</title>}i, 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.gsub!('&amp;', '&')

    # replace UTF chars like  &#187; with dummy character
    title_tag.gsub!(/&#(\d+);/, '|')

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

    return name.strip if name
  end
end

.login_from_author_pattern(text) ⇒ String

Returns The login

Parameters:

  • text (String)

Returns:

  • (String)

    The login


41
42
43
# File 'lib/common/models/wp_user/existable.rb', line 41

def self.(text)
  text[%r{/author/([^/\b]+)/?}i, 1]
end

.login_from_body(body) ⇒ String

Returns The login

Parameters:

  • body (String)

Returns:

  • (String)

    The login


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/common/models/wp_user/existable.rb', line 48

def self.(body)
  # Feed URL with Permalinks
   = WpUser::Existable.(body)

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

  
end

Instance Method Details

#exists_from_response?(response, options = {}) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)

10
11
12
13
14
# File 'lib/common/models/wp_user/existable.rb', line 10

def exists_from_response?(response, options = {})
  load_from_response(response)

  @login ? true : false
end