class Collins::AssetState

Attributes

description[RW]
id[RW]
label[RW]
name[RW]
status[RW]

Public Class Methods

from_json(json) click to toggle source
# File lib/collins/state.rb, line 9
def self.from_json json
  Collins::AssetState.new json
end
new(opts = {}) click to toggle source
# 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

Public Instance Methods

empty?() click to toggle source
# File lib/collins/state.rb, line 26
def empty?
  @id == 0
end
to_s() click to toggle source
# 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

Private Instance Methods

get_status(opt) click to toggle source
# File lib/collins/state.rb, line 39
def get_status opt
  opts = opt || {}
  hash = symbolize_hash(opts).inject({}) do |result, (k,v)|
    key = k.to_s.downcase.to_sym
    result[key] = v
    result
  end
  OpenStruct.new(hash)
end