Class: Nsf::Heading
- Defined in:
- lib/nsf.rb,
lib/nsf/formats/nsf.rb,
lib/nsf/formats/pdf.rb,
lib/nsf/formats/rtf.rb,
lib/nsf/formats/html.rb
Constant Summary collapse
- PDF_FONT_RATIOS =
[2.22222, 1.66666, 1.33333]
- PDF_HEADING_LEADING =
0.6
Instance Attribute Summary collapse
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text, level) ⇒ Heading
constructor
A new instance of Heading.
- #ref_html ⇒ Object
- #to_html ⇒ Object
- #to_nsf ⇒ Object
- #to_pdf(pdf) ⇒ Object
- #to_rtf ⇒ Object
Constructor Details
#initialize(text, level) ⇒ Heading
Returns a new instance of Heading.
63 64 65 66 |
# File 'lib/nsf.rb', line 63 def initialize(text, level) @text = text @level = level end |
Instance Attribute Details
#level ⇒ Object (readonly)
Returns the value of attribute level.
61 62 63 |
# File 'lib/nsf.rb', line 61 def level @level end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
61 62 63 |
# File 'lib/nsf.rb', line 61 def text @text end |
Class Method Details
.from_nsf(text) ⇒ Object
68 69 70 71 |
# File 'lib/nsf.rb', line 68 def self.from_nsf(text) text =~ /^(#+) (.*?)$/ self.new($2, $1.length) end |
Instance Method Details
#ref_html ⇒ Object
168 169 170 |
# File 'lib/nsf/formats/html.rb', line 168 def ref_html "heading_#{level}_#{CGI.escapeHTML(text)}" end |
#to_html ⇒ Object
164 165 166 |
# File 'lib/nsf/formats/html.rb', line 164 def to_html "<h#{level} id=\"#{ref_html}\">#{CGI.escapeHTML(text)}</h#{level}>" end |
#to_nsf ⇒ Object
31 32 33 |
# File 'lib/nsf/formats/nsf.rb', line 31 def to_nsf "#{"#" * level} #{text}" end |
#to_pdf(pdf) ⇒ Object
40 41 42 43 44 |
# File 'lib/nsf/formats/pdf.rb', line 40 def to_pdf(pdf) size = (PDF_FONT_RATIOS[level - 1] * pdf.font_size).round pdf.text text, :size => size, :leading => (size * Document::PDF_LEADING).round, :style => :bold pdf.move_down (size * PDF_HEADING_LEADING).round end |
#to_rtf ⇒ Object
65 66 67 |
# File 'lib/nsf/formats/rtf.rb', line 65 def to_rtf @text.gsub("\n", " ") end |