Class: YARP::Pack::Format

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directives, encoding) ⇒ Format

Returns a new instance of Format.



165
166
167
168
# File 'lib/yarp/pack.rb', line 165

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

Instance Attribute Details

#directivesObject (readonly)

Returns the value of attribute directives.



163
164
165
# File 'lib/yarp/pack.rb', line 163

def directives
  @directives
end

#encodingObject (readonly)

Returns the value of attribute encoding.



163
164
165
# File 'lib/yarp/pack.rb', line 163

def encoding
  @encoding
end

Instance Method Details

#describeObject



170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/yarp/pack.rb', line 170

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