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
-
.new(directives, encoding) ⇒ Format
constructor
Create a new
Format
with the given directives and encoding.
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.
# File 'lib/prism/pack.rb', line 203
def initialize(directives, encoding) @directives = directives @encoding = encoding end
Instance Attribute Details
#directives (readonly)
A list of the directives in the template.
# File 'lib/prism/pack.rb', line 197
attr_reader :directives
#encoding (readonly)
The encoding of the template.
# File 'lib/prism/pack.rb', line 200
attr_reader :encoding
Instance Method Details
#describe
Provide a human-readable description of the format.
# File 'lib/prism/pack.rb', line 209
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 " #{source.ljust(source_width)} #{directive.describe}" end (["Directives:"] + directive_lines + ["Encoding:", " #{encoding}"]).join("\n") end