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.



44
45
46
47
# File 'lib/replicate-client/hardware.rb', line 44

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

Instance Attribute Details

#nameString

The name of the hardware.

Returns:

  • (String)


37
38
39
# File 'lib/replicate-client/hardware.rb', line 37

def name
  @name
end

#skuString

The SKU of the hardware.

Returns:

  • (String)


32
33
34
# File 'lib/replicate-client/hardware.rb', line 32

def sku
  @sku
end

Class Method Details

.all(client: ReplicateClient.client) ⇒ Array<ReplicateClient::Hardware>

List all available hardware.

Parameters:

Returns:



13
14
15
16
# File 'lib/replicate-client/hardware.rb', line 13

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

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

Find hardware by SKU.

Parameters:

  • sku (String)

    The SKU of the hardware.

  • client (ReplicateClient::Client) (defaults to: ReplicateClient.client)

    The client to use for requests.

Returns:



24
25
26
# File 'lib/replicate-client/hardware.rb', line 24

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

Instance Method Details

#to_sString

Convert the hardware object to a string representation.

Returns:

  • (String)


52
53
54
# File 'lib/replicate-client/hardware.rb', line 52

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