Module: RTF

Defined in:
lib/rtf.rb

Instance Method Summary collapse

Instance Method Details

#b(string) ⇒ Object

bold text



73
74
75
76
77
78
79
# File 'lib/rtf.rb', line 73

def b(string)
  if string 
  '{\b\insrsid6900457\ccharrsid6900457 '+string+'}'
  else
    return ""
  end
end

#dotObject

returns a normal ‘.’



89
90
91
# File 'lib/rtf.rb', line 89

def dot
  '{\insrsid6900457 '+ '.' +'}'
end

#dsObject

returns a normal ‘. ’



94
95
96
# File 'lib/rtf.rb', line 94

def ds
  '{\insrsid6900457 '+ '. ' +'}'
end

returns an rtf header string



53
54
55
# File 'lib/rtf.rb', line 53

def footer
  '}'
end

#i(string) ⇒ Object

italicized text



57
58
59
60
61
62
63
# File 'lib/rtf.rb', line 57

def i(string)
  if string 
    return '{\i\insrsid6900457 ' + string + '}'
  else
    return ""
  end
end

#in_text_citation(string, font_size = 7, citation_height = 5) ⇒ Object



23
24
25
26
# File 'lib/rtf.rb', line 23

def in_text_citation(string, font_size=7, citation_height=5)
  rtf_fontsize = font_size * 2
  return '{\fs' + rtf_fontsize.to_s + '{\*\updnprop10000}\up'+ citation_height.to_s + ' ' + string.to_s + '}'
end

#insert_list_to_header(rtf_string) ⇒ Object

returns a new string with the list info embedded



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/rtf.rb', line 124

def insert_list_to_header(rtf_string)
  search_string = '{\stylesheet'
  #puts "RTF_string: " + rtf_string + "**********"
  not_interested, header = rtf_string.split(search_string)
  return rtf_string unless header
  new_string = ""
  brack_cnt = 0
  #   {stuff}{stuff}{insert my stuff}}insert list stuff
  nothing_left_to_do = false
  header.scan(/.|\n/) do |letter|
    if nothing_left_to_do
      new_string << letter
      next
    end
    if letter == "{"
      brack_cnt += 1
    elsif letter == '}'
      brack_cnt -= 1
    end
    if brack_cnt < 0
      new_string << rtf_stylesheet_insert_for_list
      new_string << '}'
      new_string << rtf_list_header
      nothing_left_to_do = true
    else
      new_string << letter
    end
  end
  new_rtf = [not_interested,new_string].join(search_string)
  return new_rtf
end

#n(string) ⇒ Object

Normal text



81
82
83
84
85
86
87
# File 'lib/rtf.rb', line 81

def n(string)
  if string 
  '{\insrsid6900457 '+string+'}'
  else
    return ""
  end
end

#newline(number) ⇒ Object



114
115
116
117
118
119
120
121
# File 'lib/rtf.rb', line 114

def newline(number)
  string = '{\insrsid13852479' + "\n"
  pars = []
  number.times {pars << '\par'}
  string << pars.join("\n")
  string << '}'
  string
end

#para(string) ⇒ Object

parenthesized: adds () around the non nil strings NOTE: will not parenthesize nil or empty (“”) string!



103
104
105
106
107
108
109
# File 'lib/rtf.rb', line 103

def para(string)
  if string && string != "" 
    return '(' + string + ')'
  else
    return ""
  end
end

#rtf_list_headerObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rtf.rb', line 33

def rtf_list_header
  # NOTE THE triple quotes are necessary to end up with: \'
  string = '
{\*\listtable{\list\listtemplateid1
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'00.;}{\levelnumbers\\\'01;}\fi-283\li283}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'01.;}{\levelnumbers\\\'01;}\fi-283\li567}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'02.;}{\levelnumbers\\\'01;}\fi-283\li850}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'03.;}{\levelnumbers\\\'01;}\fi-283\li1134}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'04.;}{\levelnumbers\\\'01;}\fi-283\li1417}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'05.;}{\levelnumbers\\\'01;}\fi-283\li1701}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'06.;}{\levelnumbers\\\'01;}\fi-283\li1984}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'07.;}{\levelnumbers\\\'01;}\fi-283\li2268}
{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'08.;}{\levelnumbers\\\'01;}\fi-283\li2551}
{\*\soutlvl{\listlevel\levelnfc0\leveljc0\levelstartat1\levelfollow2{\leveltext \\\'02\\\'09.;}{\levelnumbers\\\'01;}\fi-283\li2835}}\listid1}
}{\listoverridetable{\listoverride\listid1\listoverridecount0\ls0}}

'
end

#rtf_num_list(items, num_spacer_lines = 0) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rtf.rb', line 3

def rtf_num_list(items, num_spacer_lines=0)
  with_number = items.collect do |item|
    '\par \pard\plain {\listtext\pard\plain \li283\ri0\lin283\rin0\fi-283\f2\f2\f4 2.}\ilvl0 \ltrpar\s1\ls0\li283\ri0\lin283\rin0\fi-283\rtlch\af4\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f2\fs24\lang1033{\loch\f2\fs24\lang1033\i0\b0\*\ccs8\ccf0\rtlch\ltrch\dbch\loch\f1\fs24\lang1033 ' + item.to_s + '}'
  end

  ## Add spacers
  spacing = ""
  rtf_list_spacer = '\par \pard\plain \ltrpar\s1\li283\ri0\lin283\rin0\fi0\rtlch\af4\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f2\fs24\lang1033'
  spacer_lines = []
  num_spacer_lines.times do
    spacer_lines.push(rtf_list_spacer)
  end
  if spacer_lines.size > 0
    spacing = spacer_lines.join("\n")
  else
    spacing = ""
  end
  with_number.join(spacing)
end

#rtf_stylesheet_insert_for_listObject



29
30
31
# File 'lib/rtf.rb', line 29

def rtf_stylesheet_insert_for_list
  '{\*\ccs7\ccf0\rtlch\af3\afs24\lang255\ltrch\dbch\af2\afs24\langfe255\loch\f0\fs24\lang1033 Numbering Symbols;}'
end

#sObject

space of normal text



111
112
113
# File 'lib/rtf.rb', line 111

def s
  '{\insrsid6900457 '+ ' ' +'}'
end

#sdObject

returns a normal ‘ .’



98
99
100
# File 'lib/rtf.rb', line 98

def sd 
  '{\insrsid6900457 '+ ' .' +'}'
end

#u(string) ⇒ Object

underlined text



65
66
67
68
69
70
71
# File 'lib/rtf.rb', line 65

def u(string)
  if string 
  '{\ul\insrsid6900457\ccharrsid6900457 '+string+'}'
  else
    return ""
  end
end