Class: AbstractPresentation

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

Overview

Present abstract, highlighting keywords

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = nil) ⇒ AbstractPresentation

Returns a new instance of AbstractPresentation.



36
37
38
39
40
41
# File 'lib/abstract_presentation.rb', line 36

def initialize(text=nil)
  @text=text
  @keywords=nil
  @tag_keyword="strong"
  @class_keyword=nil
end

Instance Attribute Details

#class_keywordObject

Returns the value of attribute class_keyword.



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

def class_keyword
  @class_keyword
end

#keywordsObject

Returns the value of attribute keywords.



32
33
34
# File 'lib/abstract_presentation.rb', line 32

def keywords
  @keywords
end

#tag_keywordObject

Returns the value of attribute tag_keyword.



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

def tag_keyword
  @tag_keyword
end

#textObject

Returns the value of attribute text.



31
32
33
# File 'lib/abstract_presentation.rb', line 31

def text
  @text
end

Instance Method Details

#begin_tagObject



43
44
45
46
# File 'lib/abstract_presentation.rb', line 43

def begin_tag
  class_out= @class_keyword ? " class='#{@class_keyword}'" : ""
  "<#{@tag_keyword}#{class_out}>"
end

#end_tagObject



48
49
50
# File 'lib/abstract_presentation.rb', line 48

def end_tag
  "</#{@tag_keyword}>"
end

#html_with_keywordsObject



52
53
54
55
56
57
58
59
60
# File 'lib/abstract_presentation.rb', line 52

def html_with_keywords
  return "" if text.nil?
  out=CGI.escapeHTML(text).to_s.gsub("\n", "<br/>")
  if @keywords
    regexps=Regexp.new '('+@keywords.join("|")+')'
    out=out.gsub(regexps, "#{begin_tag}\\1#{end_tag}")
  end
  out
end