Class: Collins::AssetState

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/collins/state.rb

Constant Summary

Constants included from Util::Logging

Util::Logging::DEFAULT_LOG_FORMAT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util

#deep_copy_hash, #get_asset_or_tag, included, #require_non_empty, #require_that, #stringify_hash, #symbolize_hash

Methods included from Util::Logging

#get_logger

Constructor Details

#initialize(opts = {}) ⇒ AssetState

Returns a new instance of AssetState.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/collins/state.rb', line 13

def initialize opts = {}
  hash = symbolize_hash(opts).inject({}) do |result, (k,v)|
    key = k.to_s.downcase.to_sym
    result[key] = v
    result
  end
  @description = hash[:description].to_s
  @id = hash[:id].to_s.to_i
  @label = hash[:label].to_s
  @name = hash[:name].to_s
  @status = get_status hash[:status]
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



7
8
9
# File 'lib/collins/state.rb', line 7

def description
  @description
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/collins/state.rb', line 7

def id
  @id
end

#labelObject

Returns the value of attribute label.



7
8
9
# File 'lib/collins/state.rb', line 7

def label
  @label
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/collins/state.rb', line 7

def name
  @name
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/collins/state.rb', line 7

def status
  @status
end

Class Method Details

.from_json(json) ⇒ Object



9
10
11
# File 'lib/collins/state.rb', line 9

def self.from_json json
  Collins::AssetState.new json
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/collins/state.rb', line 26

def empty?
  @id == 0
end

#to_sObject



30
31
32
33
34
35
36
# File 'lib/collins/state.rb', line 30

def to_s
  if empty? then
    "State(None)"
  else
    "State(id = #{id}, name = '#{name}', label = '#{label}', description = '#{description}')"
  end
end