Sha256: 11e40a5df5eb248443659da7c6f956ea3454fa2dc10965ad18578aa24afa23c6

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module ObjectInspector
  # ObjectInspector::CombiningFormatter implements
  # {ObjectInspector::BaseFormatter} to return the standard/default inspect
  # output format by combining Strings.
  #
  # @attr (see BaseFormatter)
  class CombiningFormatter < BaseFormatter
    # Perform the formatting routine.
    #
    # @return [String]
    def call
      if wrapped_object_inspection_result
        build_wrapped_object_string
      else
        build_string
      end
    end

    private

    def build_wrapped_object_string
      "#{build_string} "\
      "#{ObjectInspector.configuration.presented_object_separator} "\
      "#{wrapped_object_inspection_result}"
    end

    def build_string
      "<#{combine_strings}>"
    end

    def combine_strings
      strings.join
    end

    # Override in subclasses as needed.
    def strings
      [
        build_identification_string,
        build_flags_string,
        build_info_string,
        build_name_string
      ].compact
    end

    def build_identification_string
      identification.to_s
    end

    def build_flags_string
      "(#{flags.to_s.upcase})" if flags
    end

    def build_info_string
      " #{info}" if info
    end

    def build_name_string
      " :: #{name}" if name
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
object_inspector-0.6.2 lib/object_inspector/formatters/combining_formatter.rb
object_inspector-0.6.1 lib/object_inspector/formatters/combining_formatter.rb
object_inspector-0.6.0 lib/object_inspector/formatters/combining_formatter.rb
object_inspector-0.5.2 lib/object_inspector/formatters/combining_formatter.rb