Class: ObjectIdentifier::StringFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/object_identifier/formatters/string_formatter.rb

Overview

ObjectIdentifier::StringFormatter builds a String to identify the given object(s).

Defined Under Namespace

Classes: Collection, Item

Constant Summary collapse

NO_OBJECTS_INDICATOR =

The String to output when BaseFormatter#objects is empty.

"[no objects]"

Instance Attribute Summary

Attributes inherited from BaseFormatter

#objects, #parameters

Instance Method Summary collapse

Methods inherited from BaseFormatter

call, #initialize

Constructor Details

This class inherits a constructor from ObjectIdentifier::BaseFormatter

Instance Method Details

#callString

Output the self-identifying string for the given object(s). Will either return a single object representation or a list of object representations, based on the number of objects we’re identifying.

Returns:

  • (String)

    A string that identifies the object(s).



14
15
16
17
18
19
20
21
22
# File 'lib/object_identifier/formatters/string_formatter.rb', line 14

def call
  if objects.none?
    NO_OBJECTS_INDICATOR
  elsif objects.one?
    format_item
  else # objects.size > 1
    format_collection
  end
end