Class: RD::Part

Inherits:
Object
  • Object
show all
Defined in:
lib/rd2odt/rdtool/rd/filter.rb

Overview

RD::Part is a pseudo IO class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = "", tree = nil, mode = "r") ⇒ Part

Returns a new instance of Part.



74
75
76
77
78
79
80
81
82
83
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 74

def initialize(content = "", tree = nil, mode = "r")
  @content = content
  if mode == "r"
  @content.freeze
  end
  @tree = tree
  @pos = 0
  @lineno = 0
  @unget = nil
end

Instance Attribute Details

#lineno ⇒ Object

Returns the value of attribute lineno.



71
72
73
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 71

def lineno
  @lineno
end

#pos ⇒ Object Also known as: tell

Returns the value of attribute pos.



72
73
74
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 72

def pos
  @pos
end

#tree ⇒ Object (readonly)

Returns the value of attribute tree.



70
71
72
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 70

def tree
  @tree
end

Instance Method Details

#<<(arg) ⇒ Object



195
196
197
198
199
200
201
202
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 195

def << (arg)
  begin
  @content << arg.to_s
  self
  rescue
  raise IOError
  end
end

#each_byte ⇒ Object



92
93
94
95
96
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 92

def each_byte
  while char = getc
  yield(char)
  end
end

#each_line(rs = $/) ⇒ Object Also known as: each



85
86
87
88
89
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 85

def each_line(rs = $/)
  while line = gets
  yield(line)
  end
end

#empty? ⇒ Boolean

Returns:

  • (Boolean)


241
242
243
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 241

def empty?
  @content.empty?
end

#eof? ⇒ Boolean Also known as: eof

Returns:

  • (Boolean)


98
99
100
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 98

def eof?
  @pos == @content.size
end

#getc ⇒ Object



119
120
121
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 119

def getc
  get_char(nil)
end

#gets(rs = $/) ⇒ Object



152
153
154
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 152

def gets(rs = $/)
  get_line(nil, rs)
end


204
205
206
207
208
209
210
211
212
213
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 204

def print(*args)
  begin
  args.each do |i|
    @content << i.to_s
  end
  nil
  rescue
  raise IOError
  end
end

#printf(format, *args) ⇒ Object



215
216
217
218
219
220
221
222
223
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 215

def printf(format, *args)
  str = sprintf(format, *args)
  begin
  @content << str
  nil
  rescue
  raise IOError
  end
end

#putc(char) ⇒ Object



225
226
227
228
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 225

def putc(char)
  self.printf("%c", char)
  char
end

#puts(*args) ⇒ Object



230
231
232
233
234
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 230

def puts(*args)
  args.flatten.each do |i|
  self.print(i, "\n")
  end
end

#read(length = @content.size - @pos) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 160

def read(length = @content.size - @pos)
  ret = ""
  length.times do 
  ret << getc
  end
  ret
end

#readchar ⇒ Object



123
124
125
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 123

def readchar
  get_char(true)
end

#readline(rs = $/) ⇒ Object



156
157
158
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 156

def readline(rs = $/)
  get_line(true, $/)
end

#readlines(rs = $/) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 168

def readlines(rs = $/)
  ret = []
  each_line(rs) do |line|
  ret.push(line)
  end
  ret
end

#rewind ⇒ Object



176
177
178
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 176

def rewind
  @pos = 0
end

#seek(offset, whence) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 180

def seek(offset, whence)
  case whence
  when 0
  @pos = offset
  when 1
  @pos += offset
  when 2
  @pos += @content.size - 1
  else
  raise Errno::EINVAL
  end
end

#to_s ⇒ Object



245
246
247
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 245

def to_s
  @content
end

#ungetc(char) ⇒ Object



127
128
129
130
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 127

def ungetc(char)
  @ungetc = char
  nil
end

#write(str) ⇒ Object



236
237
238
239
# File 'lib/rd2odt/rdtool/rd/filter.rb', line 236

def write(str)
  @content << str.to_s
  str.to_s.size
end