Class: Prism::Pack::Format
- Inherits:
-
Object
- Object
- Prism::Pack::Format
- Defined in:
- lib/prism/pack.rb,
ext/prism/api_pack.c
Overview
The result of parsing a pack template.
Instance Attribute Summary collapse
-
#directives ⇒ Object
readonly
A list of the directives in the template.
-
#encoding ⇒ Object
readonly
The encoding of the template.
Instance Method Summary collapse
-
#describe ⇒ Object
Provide a human-readable description of the format.
-
#initialize(directives, encoding) ⇒ Format
constructor
Create a new Format with the given directives and encoding.
Constructor Details
#initialize(directives, encoding) ⇒ Format
Create a new Format with the given directives and encoding.
206 207 208 209 |
# File 'lib/prism/pack.rb', line 206 def initialize(directives, encoding) @directives = directives @encoding = encoding end |
Instance Attribute Details
#directives ⇒ Object (readonly)
A list of the directives in the template.
200 201 202 |
# File 'lib/prism/pack.rb', line 200 def directives @directives end |
#encoding ⇒ Object (readonly)
The encoding of the template.
203 204 205 |
# File 'lib/prism/pack.rb', line 203 def encoding @encoding end |
Instance Method Details
#describe ⇒ Object
Provide a human-readable description of the format.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# 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 |