Class: HyperlinkStrategy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url = nil, options = {}) ⇒ HyperlinkStrategy

Returns a new instance of HyperlinkStrategy.



10
11
12
13
14
# File 'lib/hyperlink_strategy.rb', line 10

def initialize(url=nil, options={})
  @keywords = Set.new
  self.options = options
  self.url = url
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/hyperlink_strategy.rb', line 8

def options
  @options
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/hyperlink_strategy.rb', line 7

def url
  @url
end

Instance Method Details

#add_keyword(keyword) ⇒ Object



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

def add_keyword(keyword)
  @keywords.add(keyword)
  self
end

#decorate(keyword) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/hyperlink_strategy.rb', line 38

def decorate(keyword)
  attributes = ""
  options.each_pair do |key, value|
    attributes += " " unless attributes.length == 0
    attributes += "#{key}=\"#{value}\""
  end

  "<a " + attributes + ">#{keyword}</a>"
end

#keywordsObject



20
21
22
# File 'lib/hyperlink_strategy.rb', line 20

def keywords
  @keywords
end

#keywords=(*keywords) ⇒ Object



16
17
18
# File 'lib/hyperlink_strategy.rb', line 16

def keywords=(*keywords)
  @keywords = Set.new(keywords.flatten)
end