class ObjectIdentifier::StringFormatter::Collection
ObjectIdentifier::StringFormatter::Collection
formats a collection-specific identification String, which will also necessarily be composed of {ObjectIdentifier::StringFormatter::Item} identification Strings.
Attributes
Public Class Methods
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 44 def initialize(objects, parameters) @objects = objects @parameters = parameters end
@param objects [Object, [Object, …]] the object(s) 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 53 def call parts = objects.first(limit).map! { |obj| format_item(obj) } parts << "... (#{truncated_objects_count} more)" if truncated? parts.join(", ") end
Build a comma-separated list of formatted item Strings representing the given objects.
@return [String]
Private Instance Methods
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 61 def format_item(object) Item.new(object, parameters).call end
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 65 def limit parameters.limit { objects_count } end
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 77 def objects_count @objects_count ||= objects.size end
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 69 def truncated? truncated_objects_count.positive? end
Source
# File lib/object_identifier/formatters/string_formatter.rb, line 73 def truncated_objects_count @truncated_objects_count ||= objects_count - limit end