class Midos::Base

Attributes

auto_id[RW]
fs[RW]
io[RW]
key[RW]
le[RW]
nl[RW]
rs[RW]
vs[R]

Public Class Methods

new(options = {}, &block) click to toggle source
# File lib/midos/base.rb, line 51
def initialize(options = {}, &block)
  self.key = options[:key]

  self.rs = options.fetch(:rs, DEFAULT_RS)
  self.fs = options.fetch(:fs, DEFAULT_FS)
  self.vs = options.fetch(:vs, DEFAULT_VS)
  self.nl = options.fetch(:nl, DEFAULT_NL)
  self.le = options.fetch(:le, DEFAULT_LE)
  self.io = options.fetch(:io, self.class::DEFAULT_IO)

  @auto_id_block = options.fetch(:auto_id, block)

  reset
end

Private Class Methods

file_method(method, mode, file, options = {}, *args, &block) click to toggle source
# File lib/midos/base.rb, line 38
def file_method(method, mode, file, options = {}, *args, &block)
  Midos.open_file(file, options, mode) { |io|
    args.unshift(options.merge(io: io))
    method ? send(method, *args, &block) : block[new(*args)]
  }
end
replacements_for(*args) click to toggle source
# File lib/midos/base.rb, line 45
def replacements_for(*args)
  args.map { |a| "%#{a.bytes.map { |b| b.to_s(16) }.join.upcase}" }
end

Public Instance Methods

reset() click to toggle source
# File lib/midos/base.rb, line 70
def reset
  @auto_id = @auto_id_block ? @auto_id_block.call : default_auto_id
end

Private Instance Methods

default_auto_id(n = 0) click to toggle source
# File lib/midos/base.rb, line 76
def default_auto_id(n = 0)
  lambda { n += 1 }
end