Class: ReplicateClient::Hardware

Inherits:
Object
  • Object
show all
Defined in:
lib/replicate-client/hardware.rb

Constant Summary collapse

INDEX_PATH =
"/hardware"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ ReplicateClient::Hardware

Initialize a new hardware instance.

Parameters:

  • attributes (Hash)

    The attributes of the hardware.



41
42
43
44
# File 'lib/replicate-client/hardware.rb', line 41

def initialize(attributes)
  @sku = attributes["sku"]
  @name = attributes["name"]
end

Instance Attribute Details

#nameString

The name of the hardware.

Returns:

  • (String)


34
35
36
# File 'lib/replicate-client/hardware.rb', line 34

def name
  @name
end

#skuString

The SKU of the hardware.

Returns:

  • (String)


29
30
31
# File 'lib/replicate-client/hardware.rb', line 29

def sku
  @sku
end

Class Method Details

.allArray<ReplicateClient::Hardware>

List all available hardware.

Returns:



11
12
13
14
# File 'lib/replicate-client/hardware.rb', line 11

def all
  response = ReplicateClient.client.get(INDEX_PATH)
  response.map { |attributes| new(attributes) }
end

.find_by(sku:) ⇒ ReplicateClient::Hardware?

Find hardware by SKU.

Parameters:

  • sku (String)

    The SKU of the hardware.

Returns:



21
22
23
# File 'lib/replicate-client/hardware.rb', line 21

def find_by(sku:)
  all.find { |hardware| hardware.sku == sku }
end

Instance Method Details

#to_sString

Convert the hardware object to a string representation.

Returns:

  • (String)


49
50
51
# File 'lib/replicate-client/hardware.rb', line 49

def to_s
  "#{name} (#{sku})"
end