ypdf-writer 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +134 -0
  3. data/LICENCE +131 -0
  4. data/bin/techbook +24 -0
  5. data/demo/chunkybacon.rb +40 -0
  6. data/demo/code.rb +71 -0
  7. data/demo/colornames.rb +47 -0
  8. data/demo/demo.rb +73 -0
  9. data/demo/gettysburg.rb +66 -0
  10. data/demo/hello.rb +26 -0
  11. data/demo/individual-i.rb +89 -0
  12. data/demo/pac.rb +70 -0
  13. data/demo/qr-language.rb +580 -0
  14. data/demo/qr-library.rb +380 -0
  15. data/images/bluesmoke.jpg +0 -0
  16. data/images/chunkybacon.jpg +0 -0
  17. data/images/chunkybacon.png +0 -0
  18. data/lib/pdf/charts.rb +13 -0
  19. data/lib/pdf/charts/stddev.rb +431 -0
  20. data/lib/pdf/core_ext/mutex.rb +12 -0
  21. data/lib/pdf/math.rb +108 -0
  22. data/lib/pdf/quickref.rb +333 -0
  23. data/lib/pdf/simpletable.rb +952 -0
  24. data/lib/pdf/techbook.rb +907 -0
  25. data/lib/pdf/writer.rb +2760 -0
  26. data/lib/pdf/writer/arc4.rb +63 -0
  27. data/lib/pdf/writer/fontmetrics.rb +203 -0
  28. data/lib/pdf/writer/fonts/Courier-Bold.afm +342 -0
  29. data/lib/pdf/writer/fonts/Courier-BoldOblique.afm +342 -0
  30. data/lib/pdf/writer/fonts/Courier-Oblique.afm +342 -0
  31. data/lib/pdf/writer/fonts/Courier.afm +342 -0
  32. data/lib/pdf/writer/fonts/Helvetica-Bold.afm +2827 -0
  33. data/lib/pdf/writer/fonts/Helvetica-BoldOblique.afm +2827 -0
  34. data/lib/pdf/writer/fonts/Helvetica-Oblique.afm +3051 -0
  35. data/lib/pdf/writer/fonts/Helvetica.afm +3051 -0
  36. data/lib/pdf/writer/fonts/MustRead.html +19 -0
  37. data/lib/pdf/writer/fonts/Symbol.afm +213 -0
  38. data/lib/pdf/writer/fonts/Times-Bold.afm +2588 -0
  39. data/lib/pdf/writer/fonts/Times-BoldItalic.afm +2384 -0
  40. data/lib/pdf/writer/fonts/Times-Italic.afm +2667 -0
  41. data/lib/pdf/writer/fonts/Times-Roman.afm +2419 -0
  42. data/lib/pdf/writer/fonts/ZapfDingbats.afm +225 -0
  43. data/lib/pdf/writer/graphics.rb +813 -0
  44. data/lib/pdf/writer/graphics/imageinfo.rb +366 -0
  45. data/lib/pdf/writer/lang.rb +43 -0
  46. data/lib/pdf/writer/lang/en.rb +99 -0
  47. data/lib/pdf/writer/object.rb +23 -0
  48. data/lib/pdf/writer/object/action.rb +35 -0
  49. data/lib/pdf/writer/object/annotation.rb +42 -0
  50. data/lib/pdf/writer/object/catalog.rb +39 -0
  51. data/lib/pdf/writer/object/contents.rb +70 -0
  52. data/lib/pdf/writer/object/destination.rb +40 -0
  53. data/lib/pdf/writer/object/encryption.rb +53 -0
  54. data/lib/pdf/writer/object/font.rb +72 -0
  55. data/lib/pdf/writer/object/fontdescriptor.rb +34 -0
  56. data/lib/pdf/writer/object/fontencoding.rb +40 -0
  57. data/lib/pdf/writer/object/image.rb +305 -0
  58. data/lib/pdf/writer/object/info.rb +51 -0
  59. data/lib/pdf/writer/object/outline.rb +30 -0
  60. data/lib/pdf/writer/object/outlines.rb +30 -0
  61. data/lib/pdf/writer/object/page.rb +195 -0
  62. data/lib/pdf/writer/object/pages.rb +115 -0
  63. data/lib/pdf/writer/object/procset.rb +46 -0
  64. data/lib/pdf/writer/object/viewerpreferences.rb +74 -0
  65. data/lib/pdf/writer/ohash.rb +58 -0
  66. data/lib/pdf/writer/oreader.rb +25 -0
  67. data/lib/pdf/writer/state.rb +48 -0
  68. data/lib/pdf/writer/strokestyle.rb +138 -0
  69. data/manual.pwd +5965 -0
  70. data/readme.md +36 -0
  71. metadata +151 -0
@@ -0,0 +1,73 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ begin
12
+ require 'pdf/writer'
13
+ rescue LoadError => le
14
+ if le.message =~ %r{pdf/writer$}
15
+ $LOAD_PATH.unshift("../lib")
16
+ require 'pdf/writer'
17
+ else
18
+ raise
19
+ end
20
+ end
21
+
22
+ if ARGV.empty?
23
+ line = 'Ruby Rocks'
24
+ else
25
+ line = ARGV.join(" ")
26
+ end
27
+
28
+ pdf = PDF::Writer.new
29
+
30
+ # Do some funky stuff in the background, in a nice light blue, which is
31
+ # bound to clash with something and some red for the hell of it
32
+ x = 578
33
+ r1 = 25
34
+
35
+ 40.step(1, -3) do |xw|
36
+ tone = 1.0 - (xw / 40.0) * 0.2
37
+
38
+ pdf.stroke_style(PDF::Writer::StrokeStyle.new(xw))
39
+ pdf.stroke_color(Color::RGB.from_fraction(tone, 1, tone))
40
+ pdf.circle_at(50, 750, r1).stroke
41
+ r1 += xw
42
+ end
43
+
44
+ 40.step(1, -3) do |xw|
45
+ tone = 1.0 - (xw / 40.0) * 0.2
46
+
47
+ pdf.stroke_style(PDF::Writer::StrokeStyle.new(xw))
48
+ pdf.stroke_color(Color::RGB.from_fraction(tone, tone, 1))
49
+ pdf.line(x, 0, x, 842)
50
+ x = (x - xw - 2)
51
+ end
52
+
53
+ pdf.stroke_color(Color::RGB::Black)
54
+ pdf.stroke_style(PDF::Writer::StrokeStyle.new(1))
55
+ pdf.rectangle(20, 20, 558, 802)
56
+
57
+ y = 800
58
+ 50.step(5, -5) do |size|
59
+ height = pdf.font_height(size)
60
+ y = y - height
61
+
62
+ pdf.add_text(30, y, line, size)
63
+ end
64
+
65
+ (0...360).step(20) do |angle|
66
+ pdf.fill_color(Color::RGB.from_fraction(rand, rand, rand))
67
+
68
+ pdf.add_text(300 + Math.cos(PDF::Math.deg2rad(angle)) * 40,
69
+ 300 + Math.sin(PDF::Math.deg2rad(angle)) * 40,
70
+ line, 20, angle)
71
+ end
72
+
73
+ pdf.save_as("demo.pdf")
@@ -0,0 +1,66 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ begin
12
+ require 'pdf/writer'
13
+ rescue LoadError => le
14
+ if le.message =~ %r{pdf/writer$}
15
+ $LOAD_PATH.unshift("../lib")
16
+ require 'pdf/writer'
17
+ else
18
+ raise
19
+ end
20
+ end
21
+
22
+ pdf = PDF::Writer.new
23
+
24
+ GETTYSBURG = <<-'EOS'
25
+ Four score and seven years ago our fathers brought forth on this
26
+ continent a new nation, conceived in liberty and dedicated to the
27
+ proposition that all men are created equal. Now we are engaged in
28
+ a great civil war, testing whether that nation or any nation so
29
+ conceived and so dedicated can long endure. We are met on a great
30
+ battlefield of that war. We have come to dedicate a portion of
31
+ that field as a final resting-place for those who here gave their
32
+ lives that that nation might live. It is altogether fitting and
33
+ proper that we should do this. But in a larger sense, we cannot
34
+ dedicate, we cannot consecrate, we cannot hallow this ground.
35
+ The brave men, living and dead who struggled here have consecrated
36
+ it far above our poor power to add or detract. The world will
37
+ little note nor long remember what we say here, but it can never
38
+ forget what they did here. It is for us the living rather to be
39
+ dedicated here to the unfinished work which they who fought here
40
+ have thus far so nobly advanced. It is rather for us to be here
41
+ dedicated to the great task remaining before us�that from these
42
+ honored dead we take increased devotion to that cause for which
43
+ they gave the last full measure of devotion�that we here highly
44
+ resolve that these dead shall not have died in vain, that this
45
+ nation under God shall have a new birth of freedom, and that
46
+ government of the people, by the people, for the people shall
47
+ not perish from the earth.
48
+ EOS
49
+
50
+ gba = GETTYSBURG.split($/).join(" ").squeeze(" ")
51
+
52
+ pdf.text "The Gettysburg Address\n\n", :font_size => 36,
53
+ :justification => :center
54
+
55
+ y0 = pdf.y + 18
56
+ pdf.text gba, :justification => :full, :font_size => 14, :left => 50,
57
+ :right => 50
58
+ pdf.move_pointer(36)
59
+ pdf.text "U.S. President Abraham Lincoln, 19 November 1863",
60
+ :justification => :right, :right => 100
61
+ pdf.text "Gettysburg, Pennsylvania", :justification => :right, :right => 100
62
+
63
+ pdf.rounded_rectangle(pdf.left_margin + 25, y0, pdf.margin_width - 50,
64
+ y0 - pdf.y + 18, 10).stroke
65
+
66
+ pdf.save_as("gettysburg.pdf")
@@ -0,0 +1,26 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ begin
12
+ require 'pdf/writer'
13
+ rescue LoadError => le
14
+ if le.message =~ %r{pdf/writer$}
15
+ $LOAD_PATH.unshift("../lib")
16
+ require 'pdf/writer'
17
+ else
18
+ raise
19
+ end
20
+ end
21
+
22
+ pdf = PDF::Writer.new
23
+ pdf.select_font "Times-Roman"
24
+ pdf.text "Hello, Ruby.", :font_size => 72, :justification => :center
25
+
26
+ pdf.save_as("hello.pdf")
@@ -0,0 +1,89 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ begin
12
+ require 'pdf/writer'
13
+ rescue LoadError => le
14
+ if le.message =~ %r{pdf/writer$}
15
+ $LOAD_PATH.unshift("../lib")
16
+ require 'pdf/writer'
17
+ else
18
+ raise
19
+ end
20
+ end
21
+
22
+ require 'color/palette/monocontrast'
23
+
24
+ class IndividualI
25
+ def initialize(size = 100)
26
+ @size = size
27
+ end
28
+
29
+ # The size of the "i" in points.
30
+ attr_accessor :size
31
+
32
+ def half_i(pdf)
33
+ pdf.move_to(0, 82)
34
+ pdf.line_to(0, 78)
35
+ pdf.line_to(9, 78)
36
+ pdf.line_to(9, 28)
37
+ pdf.line_to(0, 28)
38
+ pdf.line_to(0, 23)
39
+ pdf.line_to(18, 23)
40
+ pdf.line_to(18, 82)
41
+ pdf.fill
42
+ end
43
+ private :half_i
44
+
45
+ def draw(pdf, x, y)
46
+ pdf.save_state
47
+ pdf.translate_axis(x, y)
48
+ pdf.scale_axis(1 * (@size / 100.0), -1 * (@size / 100.0))
49
+
50
+ pdf.circle_at(20, 10, 7.5)
51
+ pdf.fill
52
+
53
+ half_i(pdf)
54
+
55
+ pdf.translate_axis(40, 0)
56
+ pdf.scale_axis(-1, 1)
57
+
58
+ half_i(pdf)
59
+
60
+ pdf.restore_state
61
+ end
62
+ end
63
+
64
+ pdf = PDF::Writer.new
65
+ ii = IndividualI.new(24)
66
+
67
+ x = pdf.absolute_left_margin
68
+ y = pdf.absolute_top_margin
69
+
70
+ bg = Color::RGB.from_fraction(rand, rand, rand)
71
+ fg = Color::RGB.from_fraction(rand, rand, rand)
72
+ pal = Color::Palette::MonoContrast.new(bg, fg)
73
+
74
+ sz = 24
75
+
76
+ (-5..5).each do |col|
77
+ pdf.fill_color pal.background[col]
78
+ ii.draw(pdf, x, y)
79
+ ii.size += sz
80
+ x += sz / 2.0
81
+ y -= sz / 2.0
82
+ pdf.fill_color pal.foreground[col]
83
+ ii.draw(pdf, x, y)
84
+ x += sz / 2.0
85
+ y -= sz / 2.0
86
+ ii.size += sz
87
+ end
88
+
89
+ pdf.save_as("individual-i.pdf")
@@ -0,0 +1,70 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # Licensed under a MIT-style licence. See LICENCE in the main distribution
7
+ # for full licensing information.
8
+ #
9
+ # $Id$
10
+ #++
11
+ begin
12
+ require 'pdf/writer'
13
+ rescue LoadError => le
14
+ if le.message =~ %r{pdf/writer$}
15
+ $LOAD_PATH.unshift("../lib")
16
+ require 'pdf/writer'
17
+ else
18
+ raise
19
+ end
20
+ end
21
+
22
+ pdf = PDF::Writer.new(:orientation => :landscape)
23
+
24
+ pdf.fill_color Color::RGB::Black
25
+ pdf.rectangle(0, 0, pdf.page_width, pdf.page_height).fill
26
+
27
+ # Wall
28
+ pdf.fill_color Color::RGB::Magenta
29
+ pdf.stroke_color Color::RGB::Cyan
30
+ pdf.rounded_rectangle(20, 500, 750, 20, 10).close_fill_stroke
31
+ pdf.rounded_rectangle(20, 200, 750, 20, 10).close_fill_stroke
32
+
33
+ # Body
34
+ pdf.fill_color Color::RGB::Yellow
35
+ pdf.stroke_color Color::RGB::Black
36
+ pdf.circle_at(150, 350, 100).fill_stroke
37
+
38
+ # Mouth
39
+ pdf.fill_color Color::RGB::Black
40
+ pdf.segment_at(150, 350, 100, 100, 30, -30).close_fill_stroke
41
+
42
+ # Dot
43
+ pdf.fill_color Color::RGB::Yellow
44
+ pdf.circle_at(250, 350, 20).fill_stroke
45
+ pdf.circle_at(300, 350, 10).fill_stroke
46
+ pdf.circle_at(350, 350, 10).fill_stroke
47
+ pdf.circle_at(400, 350, 10).fill_stroke
48
+ pdf.circle_at(450, 350, 10).fill_stroke
49
+
50
+ pdf.fill_color Color::RGB::Blue
51
+ pdf.stroke_color Color::RGB::Cyan
52
+ pdf.move_to(500, 250)
53
+ pdf.line_to(500, 425)
54
+ pdf.curve_to(550, 475, 600, 475, 650, 425)
55
+ pdf.line_to(650, 250)
56
+ pdf.line_to(625, 275)
57
+ pdf.line_to(600, 250)
58
+ pdf.line_to(575, 275)
59
+ pdf.line_to(550, 250)
60
+ pdf.line_to(525, 275)
61
+ pdf.line_to(500, 250).fill_stroke
62
+
63
+ pdf.fill_color Color::RGB::White
64
+ pdf.rectangle(525, 375, 25, 25).fill
65
+ pdf.rectangle(575, 375, 25, 25).fill
66
+ pdf.fill_color Color::RGB::Black
67
+ pdf.rectangle(525, 375, 10, 10).fill
68
+ pdf.rectangle(575, 375, 10, 10).fill
69
+
70
+ pdf.save_as("pac.pdf")
@@ -0,0 +1,580 @@
1
+ #--
2
+ # PDF::Writer for Ruby.
3
+ # http://rubyforge.org/projects/ruby-pdf/
4
+ # Copyright 2003 - 2005 Austin Ziegler.
5
+ #
6
+ # This Quick Reference card program is copyright 2003�2005 Ryan
7
+ # Davis and is licensed under the Creative Commons Attribution
8
+ # NonCommercial
9
+ # ShareAlike[http://creativecommons.org/licenses/by-nc-sa/2.0/] licence.
10
+ #
11
+ # See LICENCE in the main distribution for full licensing information.
12
+ #
13
+ # $Id$
14
+ #++
15
+ begin
16
+ require 'pdf/writer'
17
+ rescue LoadError => le
18
+ if le.message =~ %r{pdf/writer$}
19
+ $LOAD_PATH.unshift("../lib")
20
+ require 'pdf/writer'
21
+ else
22
+ raise
23
+ end
24
+ end
25
+
26
+ require 'pdf/quickref'
27
+
28
+ if ARGV[0].nil?
29
+ paper = "LETTER"
30
+ else
31
+ if PDF::Writer::PAGE_SIZES.has_key?(ARGV[0])
32
+ paper = ARGV[0]
33
+ else
34
+ puts <<-EOS
35
+ usage: #{File.basename($0)} [paper-size]
36
+
37
+ paper-size must be one of the standard PDF::Writer page sizes.
38
+ Default paper-size is LETTER.
39
+ EOS
40
+ exit 0
41
+ end
42
+ end
43
+
44
+ PDF::QuickRef.make(paper, 3) do
45
+ # pdf.compressed = true
46
+ pdf.info.author = "Ryan Davis"
47
+ pdf.info.title = "Ruby Language Quick Reference"
48
+ pdf.info.subject = "The Ruby Programming Language"
49
+
50
+ self.title_font_size = 13
51
+ self.h1_font_size = 10
52
+ self.h2_font_size = 8
53
+ self.h3_font_size = 7
54
+ self.h4_font_size = 6
55
+ self.body_font_size = 5
56
+
57
+ enc = {
58
+ :encoding => 'WinAnsiEncoding',
59
+ :differences => {
60
+ 148 => "copyright",
61
+ }
62
+ }
63
+ self.title_font_encoding = enc
64
+ self.heading_font_encoding = enc
65
+ self.body_font_encoding = enc
66
+ self.code_font_encoding = enc
67
+
68
+ title "Ruby Language QuickRef"
69
+ h1 "General Syntax Rules"
70
+ lines <<-'EOS'
71
+ Comments start with a pound/sharp (#) character and go to EOL.
72
+ Lines between �=begin� and �=end� are skipped by the interpreter.
73
+ Ruby programs are sequence of expressions.
74
+ Each expression is delimited by semicolons (;) or newlines unless obviously incomplete (e.g. trailing �+�).
75
+ Backslashes at the end of line does not terminate expression.
76
+ EOS
77
+
78
+ h1 "Reserved Words"
79
+ codelines <<-'EOS'
80
+ alias and BEGIN begin break case
81
+ class def defined do else elsif
82
+ END end ensure false for if
83
+ in module next nil not or
84
+ redo rescue retry return self super
85
+ then true undef unless until when
86
+ while yield
87
+ EOS
88
+
89
+ h1 "Types"
90
+ body <<-'EOS'
91
+ Basic types are numbers, strings, ranges, regexen, symbols, arrays, and
92
+ hashes. Also included are files because they are used so often.
93
+ EOS
94
+
95
+ h2 "Numbers"
96
+ lines <<-'EOS'
97
+ 123 1_234 123.45 1.2e-3
98
+ 0xffff (hex) 0b01011 (binary) 0377 (octal)
99
+ ?a ASCII character
100
+ ?\C-a Control-a
101
+ ?\M-a Meta-a
102
+ ?\M-\C-a Meta-Control-a
103
+ EOS
104
+
105
+ h2 "Strings"
106
+ body <<-'EOS'
107
+ In all of the %() cases below, you may use any matching characters or any
108
+ single character for delimiters. %[], %!!, %@@, etc.
109
+ EOS
110
+ codelines <<-'EOS'
111
+ 'no interpolation'
112
+ "#{interpolation} and backslashes\n"
113
+ %q(no interpolation)
114
+ %Q(interpolation and backslashes)
115
+ %(interpolation and backslashes)
116
+ `echo command interpretation with interpolation and backslashes`
117
+ %x(echo command interpretation with interpolation and backslashes)
118
+ EOS
119
+
120
+ h3 "Backslashes"
121
+ pre <<-'EOS'
122
+ \t (tab), \n (newline), \r (carriage return),
123
+ \f (form feed), \b (backspace), \a (bell),
124
+ \e (escape), \s (whitespace), \nnn (octal),
125
+ \xnn (hexadecimal), \cx (control x),
126
+ \C-x (control x), \M-x (meta x),
127
+ \M-\C-x (meta control x)
128
+ EOS
129
+
130
+ h3 "Here Docs"
131
+ pre <<-'EOS'
132
+ &lt;&lt;identifier # interpolation
133
+ &lt;&lt;"identifier" # interpolation
134
+ &lt;&lt;'identifier' # no interpolation
135
+ &lt;&lt;-identifier # interpolation, indented end
136
+ &lt;&lt;-"identifier" # interpolation, indented end
137
+ &lt;&lt;-'identifier' # no interpolation, indented end
138
+ EOS
139
+
140
+ h2 "Symbols"
141
+ body <<-'EOS'
142
+ A symbol (:symbol) is an immutable name used for identifiers,
143
+ variables, and operators.
144
+ EOS
145
+
146
+ h2 "Ranges"
147
+ pre <<-'EOS'
148
+ 1..10
149
+ 'a'..'z'
150
+ (1..10) === 5 -&gt; true
151
+ (1..10) === 15 -&gt; false
152
+
153
+ # prints lines starting at 'start' and
154
+ # ending at 'end'
155
+ while gets
156
+ print if /start/../end/
157
+ end
158
+
159
+ class RangeThingy
160
+ def &lt;=&gt;(rhs)
161
+ # ...
162
+ end
163
+ def succ
164
+ # ...
165
+ end
166
+ end
167
+ range = RangeThingy.new(lower_bound) .. RangeThingy.new(upper_bound)
168
+ EOS
169
+
170
+ h2 "Regular Expressions"
171
+ pre <<-'EOS'
172
+ /normal regex/[xim]
173
+ %r|alternate form|[xim]
174
+ Regexp.new(pattern, options)
175
+ EOS
176
+ pairs <<-'EOS'
177
+ . any character except newline
178
+ [set] any single character of set
179
+ [^set] any single character NOT of set
180
+ * 0 or more previous regular expression
181
+ *? 0 or more previous regular expression (non greedy)
182
+ + 1 or more previous regular expression
183
+ +? 1 or more previous regular expression (non greedy)
184
+ ? 0 or 1 previous regular expression
185
+ | alternation
186
+ ( ) grouping regular expressions
187
+ ^ beginning of a line or string
188
+ $ end of a line or string
189
+ #{m,n} at least m but most n previous regular expression
190
+ #{m,n}? at least m but most n previous regular expression (non greedy)
191
+ \A beginning of a string
192
+ \b backspace (0x08, inside [] only)
193
+ \B non-word boundary
194
+ \b word boundary (outside [] only)
195
+ \d digit, same as[0-9]
196
+ \D non-digit
197
+ \S non-whitespace character
198
+ \s whitespace character[ \t\n\r\f]
199
+ \W non-word character
200
+ \w word character[0-9A-Za-z_]
201
+ \z end of a string
202
+ \Z end of a string, or before newline at the end
203
+ (?# ) comment
204
+ (?: ) grouping without backreferences
205
+ (?= ) zero-width positive look-ahead assertion (?! ) zero-width negative look-ahead assertion
206
+ (?ix-ix) turns on/off i/x options, localized in group if any.
207
+ (?ix-ix: ) turns on/off i/x options, localized in non-capturing group.
208
+ EOS
209
+
210
+ h2 "Arrays"
211
+ pre <<-'EOS'
212
+ [1, 2, 3]
213
+ %w(foo bar baz) # no interpolation
214
+ %W(foo #{bar} baz) # interpolation
215
+ EOS
216
+ body <<-'EOS'
217
+ Indexes may be negative, and they index backwards (-1 is the last element).
218
+ EOS
219
+
220
+ h2 "Hashes"
221
+ pre <<-'EOS'
222
+ { 1 =&gt; 2, 2 =&gt; 4, 3 =&gt; 6 }
223
+ { expr =&gt; expr, ... }
224
+ EOS
225
+
226
+ h2 "Files"
227
+ body "Common methods include:"
228
+ lines <<-'EOS'
229
+ File.join(p1, p2, ... pN) =&gt; �p1/p2/.../pN� platform independent paths
230
+ File.new(path, mode_string="r") =&gt; file
231
+ File.new(path, mode_num [, perm_num]) =&gt; file
232
+ File.open(filename, mode_string="r") {|file| block} -&gt; nil
233
+ File.open(filename [, mode_num [, perm_num ]]) {|file| block} -&gt; nil
234
+ IO.foreach(path, sepstring=$/) {|line| block}
235
+ IO.readlines(path) =&gt; array
236
+ EOS
237
+
238
+ h3 "Mode Strings"
239
+ pairs <<-'EOS'
240
+ r Read-only, starts at beginning of file (default mode).
241
+ r+ Read-write, starts at beginning of file.
242
+ w Write-only, truncates existing file to zero length or creates a new file for writing.
243
+ w+ Read-write, truncates existing file to zero length or creates a new file for reading and writing.
244
+ a Write-only, starts at end of file if file exists, otherwise creates a new file for writing.
245
+ a+ Read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.
246
+ b Binary file mode (may appear with any of the key letters listed above). Only <b>necessary</b> for DOS/Windows.
247
+ EOS
248
+
249
+ h1 "Variables and Constants"
250
+ pre <<-'EOS'
251
+ $global_variable
252
+ @instance_variable
253
+ [OtherClass::]CONSTANT
254
+ local_variable
255
+ EOS
256
+
257
+ h1 "Pseudo-variables"
258
+ pairs <<-'EOS'
259
+ self the receiver of the current method
260
+ nil the sole instance of NilClass (represents false)
261
+ true the sole instance of TrueClass (typical true value)
262
+ false the sole instance of FalseClass (represents false)
263
+ __FILE__ the current source file name.
264
+ __LINE__ the current line number in the source file.
265
+ EOS
266
+
267
+ h1 "Pre-defined Variables"
268
+ pairs <<-'EOS'
269
+ $! The exception information message set by �raise�.
270
+ $@ Array of backtrace of the last exception thrown.
271
+ $&amp; The string matched by the last successful pattern match in this scope.
272
+ $` The string to the left of the last successful match.
273
+ $' The string to the right of the last successful match.
274
+ $+ The last bracket matched by the last successful match.
275
+ $1 The Nth group of the last successful match. May be &gt; 1.
276
+ $~ The information about the last match in the current scope.
277
+ $= The flag for case insensitive, nil by default.
278
+ $/ The input record separator, newline by default.
279
+ $\ The output record separator for the print and IO#write. Default is nil.
280
+ $, The output field separator for the print and Array#join.
281
+ $; The default separator for String#split.
282
+ $. The current input line number of the last file that was read.
283
+ $&lt; The virtual concatenation file of the files given on command line.
284
+ $&gt; The default output for print, printf. $stdout by default.
285
+ $_ The last input line of string by gets or readline.
286
+ $0 Contains the name of the script being executed. May be assignable.
287
+ $* Command line arguments given for the script sans args.
288
+ $$ The process number of the Ruby running this script.
289
+ $? The status of the last executed child process.
290
+ $: Load path for scripts and binary modules by load or require.
291
+ $" The array contains the module names loaded by require.
292
+ $DEBUG The status of the -d switch.
293
+ $FILENAME Current input file from $&lt;. Same as $&lt;.filename.
294
+ $LOAD_PATH The alias to the $:.
295
+ $stderr The current standard error output.
296
+ $stdin The current standard input.
297
+ $stdout The current standard output.
298
+ $VERBOSE The verbose flag, which is set by the -v switch.
299
+ $-0 The alias to $/.
300
+ $-a True if option -a is set. Read-only variable.
301
+ $-d The alias to $DEBUG.
302
+ $-F The alias to $;.
303
+ $-i In in-place-edit mode, this variable holds the extention, otherwise nil.
304
+ $-I The alias to $:.
305
+ $-l True if option -l is set. Read-only variable.
306
+ $-p True if option -p is set. Read-only variable.
307
+ $-v The alias to $VERBOSE.
308
+ EOS
309
+
310
+ h1 "Pre-defined Global Constants"
311
+ pairs <<-'EOS'
312
+ TRUE The typical true value.
313
+ FALSE The false itself.
314
+ NIL The nil itself.
315
+ STDIN The standard input. The default value for $stdin.
316
+ STDOUT The standard output. The default value for $stdout.
317
+ STDERR The standard error output. The default value for $stderr.
318
+ ENV The hash contains current environment variables.
319
+ ARGF The alias to the $&lt;.
320
+ ARGV The alias to the $*.
321
+ DATA The file object of the script, pointing just after __END__.
322
+ RUBY_VERSION The ruby version string (VERSION was depricated).
323
+ RUBY_RELEASE_DATE The relase date string.
324
+ RUBY_PLATFORM The platform identifier.
325
+ EOS
326
+
327
+ h1 "Expressions"
328
+ h2 "Terms"
329
+ body <<-'EOS'
330
+ Terms are expressions that may be a basic type (listed above), a shell
331
+ command, variable reference, constant reference, or method invocation.
332
+ EOS
333
+
334
+ h2 "Operators and Precedence"
335
+ codelines <<-'EOS'
336
+ ::
337
+ []
338
+ **
339
+ - (unary) + (unary) ! ~
340
+ * / %
341
+ + -
342
+ &lt;&lt; &gt;&gt;
343
+ &amp;
344
+ | ^
345
+ &gt; &gt;= &lt; &lt;=
346
+ &lt;=&gt; == === != =~ !~
347
+ &amp;&amp;
348
+ ||
349
+ .. ...
350
+ = (+=, -=, ...)
351
+ not
352
+ and or
353
+ EOS
354
+
355
+ h2 "Control Expressions"
356
+ pre <<-'EOS'
357
+ if bool-expr [then]
358
+ body
359
+ elsif bool-expr [then]
360
+ body
361
+ else
362
+ body
363
+ end
364
+
365
+ unless bool-expr [then]
366
+ body
367
+ else
368
+ body
369
+ end
370
+
371
+ expr if bool-expr
372
+ expr unless bool-expr
373
+
374
+ case target-expr
375
+ # (comparisons may be regexen)
376
+ when comparison [, comparison]... [then]
377
+ body
378
+ when comparison [, comparison]... [then]
379
+ body
380
+ ...
381
+ [else
382
+ body]
383
+ end
384
+
385
+ while bool-expr [do]
386
+ body
387
+ end
388
+
389
+ until bool-expr [do]
390
+ body
391
+ end
392
+
393
+ begin
394
+ body
395
+ end while bool-expr
396
+
397
+ begin
398
+ body
399
+ end until bool-expr
400
+
401
+ for name[, name]... in expr [do]
402
+ body
403
+ end
404
+
405
+ expr.each do | name[, name]... |
406
+ body
407
+ end
408
+
409
+ expr while bool-expr
410
+ expr until bool-expr
411
+ EOS
412
+ pairs <<-'EOS'
413
+ break terminates loop immediately.
414
+ redo immediately repeats w/o rerunning the condition.
415
+ next starts the next iteration through the loop.
416
+ retry restarts the loop, rerunning the condition.
417
+ EOS
418
+
419
+ h1 "Invoking a Method"
420
+ body <<-'EOS'
421
+ Nearly everything available in a method invocation is optional, consequently
422
+ the syntax is very difficult to follow. Here are some examples:
423
+ EOS
424
+ lines <<-'EOS'
425
+ method
426
+ obj.method
427
+ Class::method
428
+ method(arg1, arg2)
429
+ method(arg1, key1 =&gt; val1, key2 =&gt; val2, aval1, aval2) { block }
430
+ method(arg1, *[arg2, arg3]) becomes: method(arg1, arg2, arg3)
431
+ EOS
432
+ pre <<-'EOS'
433
+ call := [receiver ('::' | '.')] name [params] [block]
434
+ params := ( [param]* [, hash] [*arr] [&amp;proc] )
435
+ block := { body } | do body end
436
+ EOS
437
+
438
+ h1 "Defining a Class"
439
+ body "Class names begin with capital characters."
440
+ pre <<-'EOS'
441
+ class Identifier [ &lt; Superclass ]; ... ; end
442
+
443
+ # Singleton classes, or idioclasses;
444
+ # add methods to a single instance
445
+ # obj can be self
446
+ class &lt;&lt; obj; ...; end
447
+ EOS
448
+
449
+ h1 "Defining a Module"
450
+ body "Module names begin with capital characters."
451
+ pre "module Identifier; ...; end"
452
+
453
+ h1 "Defining a Method"
454
+ pre <<-'EOS'
455
+ def method_name(arg_list); ...; end
456
+ def expr.method_name(arg_list); ...; end
457
+ EOS
458
+ lines <<-'EOS'
459
+ arg_list := ['('] [varname*] ['*' listname] ['&' blockname] [')']
460
+ Arguments may have default values (varname = expr).
461
+ Method definitions may not be nested.
462
+ method_name may be an operator: &lt;=&gt;, ==, ===, =~, &lt;, &lt;=, &gt; &gt;=, +, -, *, /, %, **, &lt;&lt;, &gt;&gt;, ~, +@, -@, [], []= (the last takes two arguments)
463
+ EOS
464
+
465
+ h2 "Access Restriction"
466
+ pairs <<-'EOS'
467
+ public totally accessable.
468
+ protected accessable only by instances of class and direct descendants. Even through hasA relationships. (see below)
469
+ private accessable only by instances of class.
470
+ EOS
471
+ body <<-'EOS'
472
+ Restriction used without arguments set the default access control. Used with
473
+ arguments, sets the access of the named methods and constants.
474
+ EOS
475
+ pre <<-'EOS'
476
+ class A
477
+ protected
478
+ def protected_method; ...; end
479
+ end
480
+ class B &lt; A
481
+ public
482
+ def test_protected
483
+ myA = A.new
484
+ myA.protected_method
485
+ end
486
+ end
487
+ b = B.new.test_protected
488
+ EOS
489
+
490
+ h3 "Accessors"
491
+ body "Module provides the following utility methods:"
492
+ pairs <<-'EOS'
493
+ attr_reader &lt;attribute&gt;[, &lt;attribute&gt;]... Creates a read-only accessor for each &lt;attribute&gt;.
494
+ attr_writer &lt;attribute&gt;[, &lt;attribute&gt;]... Creates a write-only accessor for each &lt;attribute&gt;.
495
+ attr &lt;attribute&gt; [, &lt;writable&gt;] Equivalent to "attr_reader &lt;attribute&gt;; attr_writer &lt;attribute&gt; if &lt;writable&gt;"
496
+ attr_accessor &lt;attribute&gt;[, &lt;attribute&gt;]... Equivalent to "attr &lt;attribute&gt;, true" for each argument.
497
+ EOS
498
+
499
+ h2 "Aliasing"
500
+ pre "alias &lt;old&gt; &lt;new&gt;"
501
+ body <<-'EOS'
502
+ Creates a new reference to whatever old referred to. old can be any existing
503
+ method, operator, global. It may not be a local, instance, constant, or
504
+ class variable.
505
+ EOS
506
+
507
+ h1 "Blocks, Closures, and Procs"
508
+ h2 "Blocks/Closures"
509
+ body "Blocks must follow a method invocation:"
510
+ pre <<-'EOS'
511
+ invocation do ... end
512
+ invocation do || ... end
513
+ invocation do |arg_list| ... end
514
+ invocation { ... }
515
+ invocation { || ... }
516
+ invocation { |arg_list| ... }
517
+ EOS
518
+ lines <<-'EOS'
519
+ Blocks are full closures, remembering their variable context.
520
+ Blocks are invoked via yield and may be passed arguments.
521
+ Block arguments may not have default parameters.
522
+ Brace form ({/}) has higher precedence and will bind to the last parameter if the invocation is made without parentheses.
523
+ do/end form has lower precedence and will bind to the invocation even without parentheses.
524
+ EOS
525
+
526
+ h2 "Proc Objects"
527
+ body "See class Proc for more information. Created via:"
528
+ pre <<-'EOS'
529
+ Kernel#proc (or Kernel#lambda)
530
+ Proc#new
531
+ &amp;block argument on a method
532
+ EOS
533
+
534
+ h2 "Exceptions"
535
+ pre <<-'EOS'
536
+ begin
537
+ expr
538
+ [ rescue [ exception_class [ =&gt; var ], ... ]
539
+ expr ]
540
+ [ else
541
+ expr ]
542
+ [ ensure
543
+ expr ]
544
+ end
545
+
546
+ raise [ exception_class, ] [ message ]
547
+ EOS
548
+ body <<-'EOS'
549
+ The default exception_class for rescue is StandardError, not Exception.
550
+ Raise without an exception_class raises a RuntimeError. All exception
551
+ classes must inherit from Exception or one of its children (listed below).
552
+ EOS
553
+ pairs <<-'EOS'
554
+ StandardError LocalJumpError, SystemStackError, ZeroDivisionError, RangeError (FloatDomainError), SecurityError, ThreadError, IOError (EOFError), ArgumentError, IndexError, RuntimeError, TypeError, SystemCallError (Errno::*), RegexpError
555
+ SignalException
556
+ Interrupt
557
+ NoMemoryError
558
+ ScriptError LoadError, NameError, SyntaxError, NotImplementedError
559
+ SystemExit
560
+ EOS
561
+
562
+ h2 "Catch and Throw"
563
+ pre <<-'EOS'
564
+ catch :label do
565
+ expr
566
+ throw :label
567
+ end
568
+ EOS
569
+
570
+ hline
571
+
572
+ x = pdf.absolute_right_margin + pdf.font_height(5)
573
+ y = pdf.absolute_bottom_margin
574
+ memo = %Q(Copyright � 2005 Ryan Davis with Austin Ziegler. PDF version by Austin Ziegler. Licensed under the <c:alink uri="http://creativecommons.org/licenses/by-nc-sa/2.0/">Creative Commons Attribution-NonCommercial-ShareAlike</c:alink> Licence. The original HTML version is at <c:alink uri="http://www.zenspider.com/Languages/Ruby/QuickRef.html">Zen Spider</c:alink>. Generated by <c:alink uri="http://rubyforge.org/projects/ruby-pdf/">PDF::Writer</c:alink> #{PDF::Writer::VERSION} and PDF::QuickRef #{PDF::QuickRef::VERSION}.)
575
+ pdf.add_text(x, y, memo, 5, 90)
576
+ x = pdf.absolute_right_margin - 32
577
+ y = pdf.absolute_bottom_margin + 24
578
+
579
+ save_as "Ruby-Language-QuickRef.pdf"
580
+ end