Class: Prism::Pack::Format
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.
203 204 205 206 |
# File 'lib/prism/pack.rb', line 203 def initialize(directives, encoding) @directives = directives @encoding = encoding end |
Instance Attribute Details
#directives ⇒ Object (readonly)
A list of the directives in the template.
197 198 199 |
# File 'lib/prism/pack.rb', line 197 def directives @directives end |
#encoding ⇒ Object (readonly)
The encoding of the template.
200 201 202 |
# File 'lib/prism/pack.rb', line 200 def encoding @encoding end |
Instance Method Details
#describe ⇒ Object
Provide a human-readable description of the format.
209 210 211 212 213 214 215 216 217 218 219 220 221 |
# 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 |