Class: Prism::Pack::Format

Inherits:
Object show all
Defined in:
lib/prism/pack.rb

Overview

The result of parsing a pack template.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#directivesObject (readonly)

A list of the directives in the template.



197
198
199
# File 'lib/prism/pack.rb', line 197

def directives
  @directives
end

#encodingObject (readonly)

The encoding of the template.



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

def encoding
  @encoding
end

Instance Method Details

#describeObject

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