Method: OpenC3::Structure#formatted

Defined in:
lib/openc3/packets/structure.rb

#formatted(value_type = :RAW, indent = 0, buffer = @buffer, ignored = nil) ⇒ String

Create a string that shows the name and value of each item in the structure

Parameters:

  • value_type (Symbol) (defaults to: :RAW)

    Not used. Subclasses should overload this parameter to check whether to perform conversions on the item.

  • indent (Integer) (defaults to: 0)

    Amount to indent before printing the item name

  • buffer (String) (defaults to: @buffer)

    The binary buffer to write the value to

  • ignored (Array<String>) (defaults to: nil)

    List of items to ignore when building the string

Returns:

  • (String)

    String formatted with all the item names and values



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/openc3/packets/structure.rb', line 436

def formatted(value_type = :RAW, indent = 0, buffer = @buffer, ignored = nil)
  indent_string = ' ' * indent
  string = ''
  synchronize_allow_reads(true) do
    @sorted_items.each do |item|
      next if ignored && ignored.include?(item.name)

      if (item.data_type != :BLOCK) ||
         (item.data_type == :BLOCK and value_type != :RAW and
          item.respond_to? :read_conversion and item.read_conversion)
        string << "#{indent_string}#{item.name}: #{read_item(item, value_type, buffer)}\n"
      else
        value = read_item(item, value_type, buffer)
        if String === value
          string << "#{indent_string}#{item.name}:\n"
          string << value.formatted(1, 16, ' ', indent + 2)
        else
          string << "#{indent_string}#{item.name}: #{value}\n"
        end
      end
    end
  end
  return string
end