Class: ObjectIdentifier::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/object_identifier.rb

Overview

ObjectIdentifier::Parameters encapsulates the attributes list and formatter options that may be needed for custom formatting during object identification.

Constant Summary collapse

KLASS_NOT_GIVEN =
"NOT_GIVEN"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes: [], formatter_options: {}) ⇒ Parameters

Returns a new instance of Parameters.

Parameters:

  • attributes (Array, *args) (defaults to: [])

    a list of method calls to interrogate the given object(s) with

  • formatter_options (:limit) (defaults to: {})
    Integer, nil

    (nil) a given limit on the

    number of objects to interrogate

  • formatter_options (:klass) (defaults to: {})
    #to_s

    a preferred type name for

    identifying the given object(s) as



94
95
96
97
98
99
100
# File 'lib/object_identifier.rb', line 94

def initialize(
      attributes: [],
      formatter_options: {})
  @attributes = attributes
  @limit = formatter_options.fetch(:limit, nil)
  @klass = formatter_options.fetch(:klass, KLASS_NOT_GIVEN)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



86
87
88
# File 'lib/object_identifier.rb', line 86

def attributes
  @attributes
end

Instance Method Details

#klassObject

NOTE: Expects a block if a value wasn’t supplied on initialization.



108
109
110
111
112
113
114
115
116
# File 'lib/object_identifier.rb', line 108

def klass
  if klass_given?
    @klass.to_s
  elsif block_given?
    yield.to_s
  else
    nil
  end
end

#limitObject

NOTE: Expects a block if a value wasn’t supplied on initialization.



103
104
105
# File 'lib/object_identifier.rb', line 103

def limit
  @limit || (yield if block_given?)
end