Class: HyperlinkStrategy
- Inherits:
-
Object
- Object
- HyperlinkStrategy
- Defined in:
- lib/hyperlink_strategy.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #add_keyword(keyword) ⇒ Object
- #decorate(keyword) ⇒ Object
-
#initialize(url = nil, options = {}) ⇒ HyperlinkStrategy
constructor
A new instance of HyperlinkStrategy.
- #keywords ⇒ Object
- #keywords=(*keywords) ⇒ Object
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, ={}) @keywords = Set.new self. = self.url = url end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/hyperlink_strategy.rb', line 8 def @options end |
#url ⇒ Object
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 = "" .each_pair do |key, value| attributes += " " unless attributes.length == 0 attributes += "#{key}=\"#{value}\"" end "<a " + attributes + ">#{keyword}</a>" end |
#keywords ⇒ Object
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 |