Class: Ping::Mention

Inherits:
Object
  • Object
show all
Defined in:
lib/ping/mention.rb

Constant Summary collapse

PATTERN =
%r{
  (?:^|\W)                    # beginning of string or non-word char
  @((?>[a-z0-9][a-z0-9-]*))   # @username
  (?!/)                      # without a trailing slash
  (?=
    \.+[ \t]|                 # dots followed by space or non-word character
    \.+$|                     # dots at end of line
    [^0-9a-zA-Z_.]|           # non-word character except dot
    $                         # end of line
  )
}ix.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username) ⇒ Mention

Returns a new instance of Mention.



19
20
21
# File 'lib/ping/mention.rb', line 19

def initialize(username)
  @username = username
end

Instance Attribute Details

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/ping/mention.rb', line 5

def username
  @username
end

Class Method Details

.extract(text) ⇒ Object



23
24
25
26
27
28
# File 'lib/ping/mention.rb', line 23

def self.extract(text)
  text.scan(PATTERN).flatten
      .map(&:downcase).uniq.map do |username|
        new(username)
      end
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
# File 'lib/ping/mention.rb', line 30

def ==(other)
  other == username
end

#to_sObject



34
35
36
# File 'lib/ping/mention.rb', line 34

def to_s
  username
end