Class: ReplicateClient::Hardware
- Inherits:
-
Object
- Object
- ReplicateClient::Hardware
- Defined in:
- lib/replicate-client/hardware.rb
Constant Summary collapse
- INDEX_PATH =
"/hardware"
Instance Attribute Summary collapse
-
#name ⇒ String
The name of the hardware.
-
#sku ⇒ String
The SKU of the hardware.
Class Method Summary collapse
-
.all(client: ReplicateClient.client) ⇒ Array<ReplicateClient::Hardware>
List all available hardware.
-
.find_by(sku:, client: ReplicateClient.client) ⇒ ReplicateClient::Hardware?
Find hardware by SKU.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ ReplicateClient::Hardware
constructor
Initialize a new hardware instance.
-
#to_s ⇒ String
Convert the hardware object to a string representation.
Constructor Details
#initialize(attributes) ⇒ ReplicateClient::Hardware
Initialize a new hardware instance.
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
#name ⇒ String
The name of the hardware.
37 38 39 |
# File 'lib/replicate-client/hardware.rb', line 37 def name @name end |
#sku ⇒ String
The SKU of the hardware.
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.
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.
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_s ⇒ String
Convert the hardware object to a string representation.
52 53 54 |
# File 'lib/replicate-client/hardware.rb', line 52 def to_s "#{name} (#{sku})" end |