Class: LinkHum

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

Constant Summary collapse

NOOP =
->(*){}
PROTOCOLS =
'(?:https?|ftp)'
SPLIT_PATTERN =
%r{(#{PROTOCOLS}://\p{^Space}+)}i
MAX_DISPLAY_LENGTH =
64

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ LinkHum

Returns a new instance of LinkHum.



28
29
30
31
# File 'lib/linkhum.rb', line 28

def initialize(text)
  @text = text
  @components = @text.split(SPLIT_PATTERN)
end

Class Method Details

.special(pattern = nil, &block) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/linkhum.rb', line 13

def special(pattern = nil, &block)
  return @special unless pattern

  @special and
    puts("Warning: redefining #{self}.special from #{caller.first}")

  @special = [pattern, block]
end

.urlify(text, options = {}, &block) ⇒ Object



9
10
11
# File 'lib/linkhum.rb', line 9

def urlify(text, options = {}, &block)
  new(text).urlify(options.merge(link_processor: block))
end

Instance Method Details

#urlify(options = {}) ⇒ Object



33
34
35
36
37
# File 'lib/linkhum.rb', line 33

def urlify(options = {})
  @components.map{|str|
    SPLIT_PATTERN =~ str ? process_url(str, options) : process_text(str)
  }.join
end