Class: ObjectIdentifier::StringFormatter

Inherits:
Object
  • Object
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, SingleObject

Constant Summary collapse

NO_OBJECTS_INDICATOR =
"[no objects]"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects, parameters = ObjectIdentifier.buid_parameters) ⇒ StringFormatter

Returns a new instance of StringFormatter.

Parameters:

  • objects (Object, [Object, ...])

    the object(s) to be interrogated for String values to be added to the output String

  • parameters (ObjectIdentifier::Parameters) (defaults to: ObjectIdentifier.buid_parameters)


15
16
17
18
# File 'lib/object_identifier/formatters/string_formatter.rb', line 15

def initialize(objects, parameters = ObjectIdentifier.buid_parameters)
  @objects = ObjectIdentifier::ArrayWrap.(objects)
  @parameters = parameters
end

Class Method Details

.call(objects, parameters = ObjectIdentifier.buid_parameters) ⇒ Object



8
9
10
# File 'lib/object_identifier/formatters/string_formatter.rb', line 8

def self.call(objects, parameters = ObjectIdentifier.buid_parameters)
  new(objects, parameters).call
end

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)



25
26
27
28
29
30
31
32
33
# File 'lib/object_identifier/formatters/string_formatter.rb', line 25

def call
  if @objects.none?
    NO_OBJECTS_INDICATOR
  elsif @objects.one?
    format_single_object
  else # @objects.size > 1
    format_multiple_objects
  end
end