Class: Opmac2html::ParBuilder

Inherits:
Object
  • Object
show all
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
{ '\\%' => '%', '\\#' => '#' }

Instance Method Summary collapse

Constructor Details

#initializeParBuilder

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


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 << "&bdquo;#{quote}&ldquo;"
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_sObject



43
44
45
# File 'lib/opmac2html/par_builder.rb', line 43

def to_s
  @par.join
end