Class: Collins::AssetType

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/collins/asset_type.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 = {}) ⇒ AssetType

Returns a new instance of AssetType.



13
14
15
16
17
18
19
20
21
22
# File 'lib/collins/asset_type.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
  @id = hash[:id].to_s.to_i
  @label = hash[:label].to_s
  @name = hash[:name].to_s
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.from_json(json) ⇒ Object



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

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

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/collins/asset_type.rb', line 24

def empty?
  @id == 0
end

#to_sObject



28
29
30
31
32
33
34
# File 'lib/collins/asset_type.rb', line 28

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