Class: ObjectIdentifier::Identifier
- Defined in:
- lib/object_identifier/identifier.rb
Overview
ObjectIdentifier::Identifier manages construction of the inspect String.
Defined Under Namespace
Classes: ArrayWrap
Constant Summary collapse
- NO_OBJECTS_INDICATOR =
"[no objects]"
Class Method Summary collapse
-
.identify(object, *args) ⇒ String
Class method for constructing a self-identifying string for any given object or collection of objects.
Instance Method Summary collapse
-
#initialize(objects, *args, limit: nil, klass: :not_given) ⇒ Identifier
constructor
A new instance of Identifier.
-
#to_s ⇒ String
Output the self-identifying string for an instance of ObjectIdentifier::Identifier.
Constructor Details
#initialize(objects, *args, limit: nil, klass: :not_given) ⇒ Identifier
Returns a new instance of Identifier.
46 47 48 49 50 51 |
# File 'lib/object_identifier/identifier.rb', line 46 def initialize(objects, *args, limit: nil, klass: :not_given) @objects = ArrayWrap.call(objects) @attributes = args.empty? ? [:id] : args @limit = (limit || @objects.size).to_i @klass = klass end |
Class Method Details
.self.identify(obj, *args) ⇒ String .self.identify(obj, *args, options) ⇒ String
Class method for constructing a self-identifying string for any given object or collection of objects.
42 43 44 |
# File 'lib/object_identifier/identifier.rb', line 42 def self.identify(object, *args) new(object, *args).to_s end |
Instance Method Details
#to_s ⇒ String
Output the self-identifying string for an instance of ObjectIdentifier::Identifier. Will either return a single object representation or a list of object representations, based on the number of objects we’re identifying.
59 60 61 62 63 64 65 |
# File 'lib/object_identifier/identifier.rb', line 59 def to_s if many? format_multiple_objects else format_single_object end end |