Class: AwesomePrint::Formatters::LycraAttributesFormatter

Inherits:
HashFormatter
  • Object
show all
Defined in:
lib/awesome_print/formatters/lycra_attributes_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, inspector) ⇒ LycraAttributesFormatter

Returns a new instance of LycraAttributesFormatter.



6
7
8
9
10
# File 'lib/awesome_print/formatters/lycra_attributes_formatter.rb', line 6

def initialize(attributes, inspector)
  @attributes = attributes
  @inspector = inspector
  @options = inspector.options
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/awesome_print/formatters/lycra_attributes_formatter.rb', line 4

def attributes
  @attributes
end

#inspectorObject (readonly)

Returns the value of attribute inspector.



4
5
6
# File 'lib/awesome_print/formatters/lycra_attributes_formatter.rb', line 4

def inspector
  @inspector
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/awesome_print/formatters/lycra_attributes_formatter.rb', line 4

def options
  @options
end

Instance Method Details

#formatObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/awesome_print/formatters/lycra_attributes_formatter.rb', line 12

def format
  padding = attributes.keys.map { |k| k.to_s.length }.max
  attrs = attributes.values.map do |attr|
    LycraAttributeFormatter.new(attr, inspector, padding: padding).format
  end

  if options[:multiline]
    "#{attributes.to_s} {\n#{attrs.join("\n")}\n#{outdent}}"
  else
    "#{attributes.to_s} { #{attrs.join(", ")} }"
  end
end