Class: Baikal::Hexdump::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/baikal/hexdump.rb

Overview

Describes a textual hexdump format.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes_per_row, fields, rows_per_block = 0) ⇒ Format

Creates a new Hexdump::Format instance with the specified structure. bytes_per_row specifies the number of bytes to be listed on every row; fields (a list of Hexdump::Field instances) contains the formatting rules. rows_per_block, if given and nonzero, will cause an empty line to be printed after every block of that many rows.



222
223
224
225
226
227
228
# File 'lib/baikal/hexdump.rb', line 222

def initialize bytes_per_row, fields, rows_per_block = 0
  super()
  @bytes_per_row = bytes_per_row
  @fields = fields
  @rows_per_block = rows_per_block
  return
end

Instance Attribute Details

#bytes_per_rowObject (readonly)

zero indicates no group separation



212
213
214
# File 'lib/baikal/hexdump.rb', line 212

def bytes_per_row
  @bytes_per_row
end

#fieldsObject (readonly)

Returns the value of attribute fields.



213
214
215
# File 'lib/baikal/hexdump.rb', line 213

def fields
  @fields
end

#rows_per_blockObject (readonly)

zero indicates no block separation



211
212
213
# File 'lib/baikal/hexdump.rb', line 211

def rows_per_block
  @rows_per_block
end

Instance Method Details

#format_row(row, port) ⇒ Object

Formats a given row (an instance of Hexdump::Row) according to formatting rules embodied in this Hexdump_Format instance and outputs the result into the given port



235
236
237
238
239
# File 'lib/baikal/hexdump.rb', line 235

def format_row row, port
  raise 'Type mismatch' unless row.is_a? Hexdump::Row
  port.puts @fields.map{|field| field.format(row)}.join('')
  return
end