123456789_123456789_123456789_123456789_123456789_

Class: Prism::Pack::Format

Relationships & Source Files
Inherits: Object
Defined in: lib/prism/pack.rb,
prism/api_pack.c

Overview

The result of parsing a pack template.

Class Method Summary

Instance Attribute Summary

  • #directives readonly

    A list of the directives in the template.

  • #encoding readonly

    The encoding of the template.

Instance Method Summary

  • #describe

    Provide a human-readable description of the format.

Constructor Details

.new(directives, encoding) ⇒ Format

Create a new Format with the given directives and encoding.

[ GitHub ]

  
# File 'lib/prism/pack.rb', line 206

def initialize(directives, encoding)
  @directives = directives
  @encoding = encoding
end

Instance Attribute Details

#directives (readonly)

A list of the directives in the template.

[ GitHub ]

  
# File 'lib/prism/pack.rb', line 200

attr_reader :directives

#encoding (readonly)

The encoding of the template.

[ GitHub ]

  
# File 'lib/prism/pack.rb', line 203

attr_reader :encoding

Instance Method Details

#describe

Provide a human-readable description of the format.

[ GitHub ]

  
# File 'lib/prism/pack.rb', line 212

def describe
  source_width = directives.map { |d| d.source.inspect.length }.max
  directive_lines = directives.map do |directive|
    if directive.type == SPACE
      source = directive.source.inspect
    else
      source = directive.source
    end
    # @type var source_width: Integer
    "  #{source.ljust(source_width)}  #{directive.describe}"
  end

  (["Directives:"] + directive_lines + ["Encoding:", "  #{encoding}"]).join("\n")
end