Class: AmazingPrint::Formatters::HashFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- AmazingPrint::Formatters::HashFormatter
- Includes:
- JSONHelper
- Defined in:
- lib/amazing_print/formatters/hash_formatter.rb
Defined Under Namespace
Classes: InvalidHashFormatError
Constant Summary collapse
- VALID_HASH_FORMATS =
i[json rocket symbol].freeze
Constants included from JSONHelper
JSONHelper::VALUE_CLASSES_NOT_TO_CONVERT
Constants inherited from BaseFormatter
BaseFormatter::DEFAULT_LIMIT_SIZE, BaseFormatter::INDENT_CACHE
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#inspector ⇒ Object
readonly
Returns the value of attribute inspector.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(hash, inspector) ⇒ HashFormatter
constructor
A new instance of HashFormatter.
Methods included from JSONHelper
Methods inherited from BaseFormatter
#align, #colorless, #colorless_size, #get_limit_size, #indent, #indentation, #indented, #limited, #method_tuple, #outdent, #should_be_limited?
Methods included from Colorize
Constructor Details
#initialize(hash, inspector) ⇒ HashFormatter
Returns a new instance of HashFormatter.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/amazing_print/formatters/hash_formatter.rb', line 17 def initialize(hash, inspector) super() @hash = hash @inspector = inspector = inspector. return if VALID_HASH_FORMATS.include?([:hash_format]) raise(InvalidHashFormatError, "Invalid hash_format: #{options[:hash_format].inspect}. " \ "Must be one of #{VALID_HASH_FORMATS}") end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
15 16 17 |
# File 'lib/amazing_print/formatters/hash_formatter.rb', line 15 def hash @hash end |
#inspector ⇒ Object (readonly)
Returns the value of attribute inspector.
15 16 17 |
# File 'lib/amazing_print/formatters/hash_formatter.rb', line 15 def inspector @inspector end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/amazing_print/formatters/hash_formatter.rb', line 15 def end |
Instance Method Details
#format ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/amazing_print/formatters/hash_formatter.rb', line 29 def format if hash.empty? empty_hash elsif multiline_hash? multiline_hash else simple_hash end end |