Class: FoldingAtHomeClient::GPU

Inherits:
Object
  • Object
show all
Extended by:
Request
Defined in:
lib/folding_at_home_client/gpu.rb

Constant Summary

Constants included from Request

Request::API_URL, Request::HEADERS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Request

connection, format_response, request, request_and_instantiate_objects, request_unencoded

Constructor Details

#initialize(vendor: nil, device: nil, type: nil, species: nil, description: nil, error: nil) ⇒ GPU

Returns a new instance of GPU.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/folding_at_home_client/gpu.rb', line 14

def initialize(
  vendor: nil,
  device: nil,
  type: nil,
  species: nil,
  description: nil,
  error: nil
)
  @vendor = vendor
  @device = device
  @type = type if type
  @species = species if species
  @description = description if description

  @error = error if error
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/folding_at_home_client/gpu.rb', line 7

def description
  @description
end

#deviceObject (readonly)

Returns the value of attribute device.



7
8
9
# File 'lib/folding_at_home_client/gpu.rb', line 7

def device
  @device
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/folding_at_home_client/gpu.rb', line 7

def error
  @error
end

#speciesObject (readonly)

Returns the value of attribute species.



7
8
9
# File 'lib/folding_at_home_client/gpu.rb', line 7

def species
  @species
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/folding_at_home_client/gpu.rb', line 7

def type
  @type
end

#vendorObject (readonly)

Returns the value of attribute vendor.



7
8
9
# File 'lib/folding_at_home_client/gpu.rb', line 7

def vendor
  @vendor
end

Class Method Details

.find_by(vendor:, device:) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/folding_at_home_client/gpu.rb', line 31

def self.find_by(vendor:, device:)
  endpoint = "/gpus/#{vendor}/#{device}"
  gpu_hash = request(endpoint:).first

  gpu_hash[:vendor] = vendor
  gpu_hash[:device] = device

  error = gpu_hash[:error]
  gpu_hash.delete(:status) if error

  new_gpu = allocate
  new_gpu.send(:initialize, **gpu_hash)

  new_gpu
end