Class: Baikal::Hexdump::Format
- Inherits:
-
Object
- Object
- Baikal::Hexdump::Format
- Defined in:
- lib/baikal/hexdump.rb
Overview
Describes a textual hexdump format.
Instance Attribute Summary collapse
-
#bytes_per_row ⇒ Object
readonly
zero indicates no group separation.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#rows_per_block ⇒ Object
readonly
zero indicates no block separation.
Instance Method Summary collapse
-
#format_row(row, port) ⇒ Object
Formats a given
row(an instance ofHexdump::Row) according to formatting rules embodied in thisHexdump_Formatinstance and outputs the result into the givenport. -
#initialize(bytes_per_row, fields, rows_per_block = 0) ⇒ Format
constructor
Creates a new
Hexdump::Formatinstance with the specified structure.
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_row ⇒ Object (readonly)
zero indicates no group separation
212 213 214 |
# File 'lib/baikal/hexdump.rb', line 212 def bytes_per_row @bytes_per_row end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
213 214 215 |
# File 'lib/baikal/hexdump.rb', line 213 def fields @fields end |
#rows_per_block ⇒ Object (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 |