Class: Prism::Pack::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/prism/pack.rb,
ext/prism/api_pack.c

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.



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

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

Instance Attribute Details

#directivesObject (readonly)

A list of the directives in the template.



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

def directives
  @directives
end

#encodingObject (readonly)

The encoding of the template.



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

def encoding
  @encoding
end

Instance Method Details

#describeObject

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