Class: AIA::ModelSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/aia/config/model_spec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#instanceObject

Returns the value of attribute instance.



16
17
18
# File 'lib/aia/config/model_spec.rb', line 16

def instance
  @instance
end

#internal_idObject

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

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/aia/config/model_spec.rb', line 16

def name
  @name
end

#roleObject

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

Returns:

  • (Boolean)


63
64
65
# File 'lib/aia/config/model_spec.rb', line 63

def duplicate?
  @instance > 1
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/aia/config/model_spec.rb', line 49

def eql?(other)
  self == other
end

#hashObject



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

Returns:

  • (Boolean)


58
59
60
# File 'lib/aia/config/model_spec.rb', line 58

def role?
  !@role.nil? && !@role.empty?
end

#to_hObject



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_sObject



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