Class: ObjectIdentifier::Identifier
- Defined in:
- lib/object_identifier/identifier.rb
Constant Summary collapse
- NO_OBJECTS_INDICATOR =
"[no objects]".freeze
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.
41 42 43 44 45 46 |
# File 'lib/object_identifier/identifier.rb', line 41 def initialize(objects, *args, limit: nil, klass: :not_given) @objects = Array(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.
37 38 39 |
# File 'lib/object_identifier/identifier.rb', line 37 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.
54 55 56 57 58 59 60 |
# File 'lib/object_identifier/identifier.rb', line 54 def to_s if many? format_multiple_objects else format_single_object end end |