class IOUnpack

Constants

DirectivePattern
DirectiveRegexp
Directives

Attributes

len[R]
pattern[R]

Public Class Methods

new(pattern) click to toggle source
# File lib/iounpack.rb, line 75
def initialize pattern
  @len, @pattern = 0, pattern
  loop do
    case pattern
    when /\A\s*\z/m then break
    when DirectiveRegexp
      pattern = $'
      m = [Directives[$~[:directive]], $~[:count] ? $~[:count].to_i : 1]
      @len += m.first * m.last
    else
      raise ArgumentError, "Unknown token: #{pattern[0]}"
    end
  end
end

Public Instance Methods

unpack(io) click to toggle source
# File lib/iounpack.rb, line 90
def unpack io
  io.read( @len).unpack @pattern
end
unpack1(io) click to toggle source
# File lib/iounpack.rb, line 94
def unpack1 io
  io.read( @len).unpack1 @pattern
end