Class: AIA::ModelSpec
- Inherits:
-
Object
- Object
- AIA::ModelSpec
- Defined in:
- lib/aia/config/model_spec.rb
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#internal_id ⇒ Object
Returns the value of attribute internal_id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#role ⇒ Object
Returns the value of attribute role.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#duplicate? ⇒ Boolean
Check if this is a duplicate instance of the same model.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(hash = {}) ⇒ ModelSpec
constructor
A new instance of ModelSpec.
-
#role? ⇒ Boolean
Check if this model has a role assigned.
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ ModelSpec
Returns a new instance of ModelSpec.
18 19 20 21 22 23 24 25 |
# File 'lib/aia/config/model_spec.rb', line 18 def initialize(hash = {}) hash = hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys) @name = hash[:name] @role = hash[:role] @instance = hash[:instance] || 1 @internal_id = hash[:internal_id] || @name end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
16 17 18 |
# File 'lib/aia/config/model_spec.rb', line 16 def instance @instance end |
#internal_id ⇒ Object
Returns the value of attribute internal_id.
16 17 18 |
# File 'lib/aia/config/model_spec.rb', line 16 def internal_id @internal_id end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/aia/config/model_spec.rb', line 16 def name @name end |
#role ⇒ Object
Returns the value of attribute role.
16 17 18 |
# File 'lib/aia/config/model_spec.rb', line 16 def role @role end |
Instance Method Details
#==(other) ⇒ Object
44 45 46 47 |
# File 'lib/aia/config/model_spec.rb', line 44 def ==(other) return false unless other.is_a?(ModelSpec) name == other.name && role == other.role && instance == other.instance end |
#duplicate? ⇒ Boolean
Check if this is a duplicate instance of the same model
63 64 65 |
# File 'lib/aia/config/model_spec.rb', line 63 def duplicate? @instance > 1 end |
#eql?(other) ⇒ Boolean
49 50 51 |
# File 'lib/aia/config/model_spec.rb', line 49 def eql?(other) self == other end |
#hash ⇒ Object
53 54 55 |
# File 'lib/aia/config/model_spec.rb', line 53 def hash [name, role, instance].hash end |
#role? ⇒ Boolean
Check if this model has a role assigned
58 59 60 |
# File 'lib/aia/config/model_spec.rb', line 58 def role? !@role.nil? && !@role.empty? end |
#to_h ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/aia/config/model_spec.rb', line 27 def to_h { name: @name, role: @role, instance: @instance, internal_id: @internal_id } end |
#to_s ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/aia/config/model_spec.rb', line 36 def to_s if @role "#{@name}=#{@role}" else @name.to_s end end |