Class: BRS::Stream::Abstract

Inherits:
Object
  • Object
show all
Includes:
Delegates
Defined in:
lib/brs/stream/abstract.rb

Direct Known Subclasses

Reader, Writer

Constant Summary

Constants included from Delegates

Delegates::DELEGATES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegates

included

Constructor Details

#initialize(io, options = {}) ⇒ Abstract



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/brs/stream/abstract.rb', line 25

def initialize(io, options = {})
  @raw_stream = create_raw_stream
  @io         = io

  @stat = Stat.new @io.stat if @io.respond_to? :stat

  set_encoding options[:external_encoding], options[:internal_encoding], options[:transcode_options]
  reset_buffer
  reset_io_advise

  @pos = 0
end

Instance Attribute Details

#external_encodingObject (readonly)

Returns the value of attribute external_encoding.



21
22
23
# File 'lib/brs/stream/abstract.rb', line 21

def external_encoding
  @external_encoding
end

#internal_encodingObject (readonly)

Returns the value of attribute internal_encoding.



21
22
23
# File 'lib/brs/stream/abstract.rb', line 21

def internal_encoding
  @internal_encoding
end

#ioObject (readonly)

Returns the value of attribute io.



21
22
23
# File 'lib/brs/stream/abstract.rb', line 21

def io
  @io
end

#posObject (readonly) Also known as: tell

Returns the value of attribute pos.



21
22
23
# File 'lib/brs/stream/abstract.rb', line 21

def pos
  @pos
end

#statObject (readonly)

Returns the value of attribute stat.



21
22
23
# File 'lib/brs/stream/abstract.rb', line 21

def stat
  @stat
end

#transcode_optionsObject (readonly)

Returns the value of attribute transcode_options.



21
22
23
# File 'lib/brs/stream/abstract.rb', line 21

def transcode_options
  @transcode_options
end

Instance Method Details

#adviseObject



53
54
55
56
# File 'lib/brs/stream/abstract.rb', line 53

def advise
  # Noop
  nil
end

#closeObject



135
136
137
138
139
# File 'lib/brs/stream/abstract.rb', line 135

def close
  @io.close if @io.respond_to? :close

  nil
end

#closed?Boolean



141
142
143
144
145
146
147
148
149
# File 'lib/brs/stream/abstract.rb', line 141

def closed?
  return false unless @raw_stream.closed?

  if @io.respond_to? :closed
    @io.closed?
  else
    true
  end
end

#rewindObject

– etc –



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/brs/stream/abstract.rb', line 122

def rewind
  @raw_stream = create_raw_stream

  @io.rewind if @io.respond_to? :rewind

  reset_buffer
  reset_io_advise

  @pos = 0

  0
end

#set_encoding(*args) ⇒ Object

– encoding –



60
61
62
63
64
65
66
67
68
# File 'lib/brs/stream/abstract.rb', line 60

def set_encoding(*args)
  external_encoding, internal_encoding, transcode_options = process_set_encoding_arguments(*args)

  set_target_encoding :@external_encoding, external_encoding
  set_target_encoding :@internal_encoding, internal_encoding
  @transcode_options = transcode_options

  self
end

#to_ioObject



151
152
153
# File 'lib/brs/stream/abstract.rb', line 151

def to_io
  self
end