Class: AwesomePrint::Formatters::LycraAttributeFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/awesome_print/formatters/lycra_attribute_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, inspector, padding: 0) ⇒ LycraAttributeFormatter

TODO mappings (maybe refactor attribute(s) to accept the document and behave differently if they’re a document attribute or not)



8
9
10
11
12
13
# File 'lib/awesome_print/formatters/lycra_attribute_formatter.rb', line 8

def initialize(attribute, inspector, padding: 0)
  @attribute = attribute
  @inspector = inspector
  @options = inspector.options
  @padding = padding
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



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

def attribute
  @attribute
end

#inspectorObject (readonly)

Returns the value of attribute inspector.



4
5
6
# File 'lib/awesome_print/formatters/lycra_attribute_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_attribute_formatter.rb', line 4

def options
  @options
end

#paddingObject (readonly)

Returns the value of attribute padding.



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

def padding
  @padding
end

Instance Method Details

#formatObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/awesome_print/formatters/lycra_attribute_formatter.rb', line 15

def format
  if options[:multiline]
    [ 
      name_and_type,
      indent + (' ' * (padding + 1)) + description,
      #indent + (' ' * (padding + 1)) + mappings
    ].join("\n")
  else
    "#{name_and_type} #{description}" #{mappings}"
  end
end