Class: ObjectIdentifier::Parameters
- Defined in:
- lib/object_identifier/parameters.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 =
This String to display if ‘formatter_options` isn’t present.
"NOT_GIVEN"
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.build(attributes: [], formatter_options: {}) ⇒ Object
Factory method for building an Parameters object.
Instance Method Summary collapse
-
#initialize(attributes: [], formatter_options: {}) ⇒ Parameters
constructor
A new instance of Parameters.
-
#klass ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
-
#limit ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
Constructor Details
#initialize(attributes: [], formatter_options: {}) ⇒ Parameters
Returns a new instance of Parameters.
31 32 33 34 35 36 37 |
# File 'lib/object_identifier/parameters.rb', line 31 def initialize( attributes: [], formatter_options: {}) @attributes = attributes @limit = .fetch(:limit, nil) @klass = .fetch(:klass, KLASS_NOT_GIVEN) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/object_identifier/parameters.rb', line 10 def attributes @attributes end |
Class Method Details
.build(attributes: [], formatter_options: {}) ⇒ Object
Factory method for building an ObjectIdentifier::Parameters object. Uses ObjectIdentifier.default_attributes if the given ‘attributes` array is empty.
15 16 17 18 19 20 21 22 23 |
# File 'lib/object_identifier/parameters.rb', line 15 def self.build(attributes: [], formatter_options: {}) attrs = ObjectIdentifier::ArrayWrap.(attributes) attrs = ObjectIdentifier.default_attributes if attrs.empty? attrs.flatten! new( attributes: attrs, formatter_options: .to_h) end |
Instance Method Details
#klass ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
45 46 47 48 49 50 51 52 53 |
# File 'lib/object_identifier/parameters.rb', line 45 def klass if klass_given? @klass.to_s elsif block_given? yield.to_s else nil end end |
#limit ⇒ Object
NOTE: Expects a block if a value wasn’t supplied on initialization.
40 41 42 |
# File 'lib/object_identifier/parameters.rb', line 40 def limit @limit || (yield if block_given?) end |