class Comet::DiskDrive

DiskDrive is a typed class wrapper around the underlying Comet Server API data structure.

Attributes

caption[RW]

@type [String] caption

cylinders[RW]

@type [Number] cylinders

device_name[RW]

@type [String] device_name

flags[RW]

@type [Number] flags

heads[RW]

@type [Number] heads

id[RW]

@type [String] id

model[RW]

@type [String] model

partitions[RW]

@type [Array<Comet::Partition>] partitions

sector_size[RW]

@type [Number] sector_size

sectors[RW]

@type [Number] sectors

serial_number[RW]

@type [String] serial_number

size[RW]

@type [Number] size

unknown_json_fields[RW]

@type [Hash] Hidden storage to preserve future properties for non-destructive roundtrip operations

Public Class Methods

new() click to toggle source
# File lib/comet/models/disk_drive.rb, line 56
def initialize
  clear
end

Public Instance Methods

clear() click to toggle source
# File lib/comet/models/disk_drive.rb, line 60
def clear
  @id = ''
  @device_name = ''
  @caption = ''
  @model = ''
  @serial_number = ''
  @size = 0
  @partitions = []
  @flags = 0
  @cylinders = 0
  @heads = 0
  @sectors = 0
  @sector_size = 0
  @unknown_json_fields = {}
end
from_hash(obj) click to toggle source

@param [Hash] obj The complete object as a Ruby hash

# File lib/comet/models/disk_drive.rb, line 84
def from_hash(obj)
  raise TypeError, "'obj' expected Hash, got #{obj.class}" unless obj.is_a? Hash

  obj.each do |k, v|
    case k
    when 'ID'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @id = v
    when 'DeviceName'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @device_name = v
    when 'Caption'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @caption = v
    when 'Model'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @model = v
    when 'SerialNumber'
      raise TypeError, "'v' expected String, got #{v.class}" unless v.is_a? String

      @serial_number = v
    when 'Size'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @size = v
    when 'Partitions'
      if v.nil?
        @partitions = []
      else
        @partitions = Array.new(v.length)
        v.each_with_index do |v1, i1|
          @partitions[i1] = Comet::Partition.new
          @partitions[i1].from_hash(v1)
        end
      end
    when 'Flags'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @flags = v
    when 'Cylinders'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @cylinders = v
    when 'Heads'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @heads = v
    when 'Sectors'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @sectors = v
    when 'SectorSize'
      raise TypeError, "'v' expected Numeric, got #{v.class}" unless v.is_a? Numeric

      @sector_size = v
    else
      @unknown_json_fields[k] = v
    end
  end
end
from_json(json_string) click to toggle source

@param [String] json_string The complete object in JSON format

# File lib/comet/models/disk_drive.rb, line 77
def from_json(json_string)
  raise TypeError, "'json_string' expected String, got #{json_string.class}" unless json_string.is_a? String

  from_hash(JSON.parse(json_string))
end
to_h() click to toggle source

@return [Hash] The complete object as a Ruby hash

# File lib/comet/models/disk_drive.rb, line 171
def to_h
  to_hash
end
to_hash() click to toggle source

@return [Hash] The complete object as a Ruby hash

# File lib/comet/models/disk_drive.rb, line 150
def to_hash
  ret = {}
  ret['ID'] = @id
  ret['DeviceName'] = @device_name
  ret['Caption'] = @caption
  ret['Model'] = @model
  ret['SerialNumber'] = @serial_number
  ret['Size'] = @size
  ret['Partitions'] = @partitions
  ret['Flags'] = @flags
  ret['Cylinders'] = @cylinders
  ret['Heads'] = @heads
  ret['Sectors'] = @sectors
  ret['SectorSize'] = @sector_size
  @unknown_json_fields.each do |k, v|
    ret[k] = v
  end
  ret
end
to_json(options = {}) click to toggle source

@return [String] The complete object as a JSON string

# File lib/comet/models/disk_drive.rb, line 176
def to_json(options = {})
  to_hash.to_json(options)
end