Class: ObjectIdentifier::StringFormatter
- Defined in:
- lib/object_identifier/formatters/string_formatter.rb
Overview
ObjectIdentifier::StringFormatter builds a String to identify the given object(s).
Constant Summary collapse
- NO_OBJECTS_INDICATOR =
"[no objects]"- KLASS_NOT_GIVEN =
"NOT_GIVEN"
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ String
Output the self-identifying string for the given object(s).
-
#initialize(objects, attributes = ObjectIdentifier::Identifier.default_attributes, limit: nil, klass: KLASS_NOT_GIVEN) ⇒ StringFormatter
constructor
A new instance of StringFormatter.
Constructor Details
#initialize(objects, attributes = ObjectIdentifier::Identifier.default_attributes, limit: nil, klass: KLASS_NOT_GIVEN) ⇒ StringFormatter
Returns a new instance of StringFormatter.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/object_identifier/formatters/string_formatter.rb', line 21 def initialize( objects, attributes = ObjectIdentifier::Identifier.default_attributes, limit: nil, klass: KLASS_NOT_GIVEN) @objects = ObjectIdentifier::ArrayWrap.(objects) @attributes = ObjectIdentifier::ArrayWrap.(attributes) @limit = (limit || @objects.size).to_i @klass = klass.to_s end |
Class Method Details
.call(objects, *attributes, **kargs) ⇒ Object
9 10 11 |
# File 'lib/object_identifier/formatters/string_formatter.rb', line 9 def self.call(objects, *attributes, **kargs) new(objects, *attributes, **kargs).call end |
Instance Method Details
#call ⇒ String
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.
37 38 39 40 41 42 43 |
# File 'lib/object_identifier/formatters/string_formatter.rb', line 37 def call return NO_OBJECTS_INDICATOR if @objects.empty? output_strings = @objects.first(@limit).map { |obj| format(obj) } output_strings << "... (#{truncated_objects_count} more)" if truncated? output_strings.join(", ") end |