class ObjectIdentifier::StringFormatter::Item
ObjectIdentifier::StringFormatter::Item
formats a single-object-specific identification String.
Attributes
Public Class Methods
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 91 def initialize(object, parameters) @object = object @parameters = parameters end
@param object [Object] The object to be interrogated for String values to
be added to the output String.
@param parameters [ObjectIdentifier::Parameters]
Public Instance Methods
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 97 def call return NO_OBJECTS_INDICATOR if blank? "#{class_name}[#{formatted_attributes}]" end
@return [String] The self-identifying String for {#object}.
Private Instance Methods
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 145 def attributes parameters.attributes end
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 122 def attributes_formatter @attributes_formatter ||= if attributes_hash.one? ->(_key, value) { value.inspect } else # attributes_hash.size > 1 ->(key, value) { "#{key}:#{value.inspect}" } end end
:reek: DuplicateMethodCall
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 134 def attributes_hash @attributes_hash ||= attributes.each_with_object({}) { |key, acc| if object.respond_to?(key, :include_private) acc[key] = object.__send__(key) elsif key.to_s.start_with?("@") acc[key] = object.instance_variable_get(key) end } end
@return [Hash]
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 108 def blank? object.nil? || object == [] || object == {} end
Simple version of Rails’ Object#blank? method.
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 112 def class_name parameters.class { object.class.name } end
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 116 def formatted_attributes attributes_hash.map(&attributes_formatter).join(", ") end