Class: Opmac2html::ParBuilder
- Inherits:
-
Object
- Object
- Opmac2html::ParBuilder
- Defined in:
- lib/opmac2html/par_builder.rb
Overview
Paragraph builder
Constant Summary collapse
- ELEM =
-> (name, text) { "<#{name}>#{text}</#{name}>" }
- ELEM_WITH_ATT =
lambda do |name, attname, attval, text| "<#{name} #{attname}=\"#{attval}\">#{text}</#{name}>" end
- LINK_SUBS =
{ '\\%' => '%', '\\#' => '#' }
Instance Method Summary collapse
- #add_code(code) ⇒ Object
- #add_em(text) ⇒ Object
- #add_link(address, text = nil) ⇒ Object
- #add_quote(quote) ⇒ Object
- #add_strong(text) ⇒ Object
- #add_verbatim(text) ⇒ Object
- #add_word(word) ⇒ Object
-
#initialize ⇒ ParBuilder
constructor
A new instance of ParBuilder.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ ParBuilder
Returns a new instance of ParBuilder.
10 11 12 |
# File 'lib/opmac2html/par_builder.rb', line 10 def initialize @par = [] end |
Instance Method Details
#add_code(code) ⇒ Object
18 19 20 |
# File 'lib/opmac2html/par_builder.rb', line 18 def add_code(code) @par << ELEM.call('code', code) end |
#add_em(text) ⇒ Object
26 27 28 |
# File 'lib/opmac2html/par_builder.rb', line 26 def add_em(text) @par << ELEM.call('em', text) end |
#add_link(address, text = nil) ⇒ Object
34 35 36 37 |
# File 'lib/opmac2html/par_builder.rb', line 34 def add_link(address, text = nil) address.gsub!(/\\[%#]/) { |c| LINK_SUBS[c] } @par << ELEM_WITH_ATT.call('a', 'href', address, text ? text : address) end |
#add_quote(quote) ⇒ Object
22 23 24 |
# File 'lib/opmac2html/par_builder.rb', line 22 def add_quote(quote) @par << "„#{quote}“" end |
#add_strong(text) ⇒ Object
30 31 32 |
# File 'lib/opmac2html/par_builder.rb', line 30 def add_strong(text) @par << ELEM.call('strong', text) end |
#add_verbatim(text) ⇒ Object
39 40 41 |
# File 'lib/opmac2html/par_builder.rb', line 39 def add_verbatim(text) @par << ELEM.call('pre', text) end |
#add_word(word) ⇒ Object
14 15 16 |
# File 'lib/opmac2html/par_builder.rb', line 14 def add_word(word) @par << word end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/opmac2html/par_builder.rb', line 43 def to_s @par.join end |