Class: Arcp::Lease::LeaseRequest

Inherits:
Data
  • Object
show all
Defined in:
lib/arcp/lease.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capabilities:, budget: nil, model_use: nil, expires_at: nil) ⇒ LeaseRequest

Returns a new instance of LeaseRequest.



81
82
83
84
85
86
87
88
# File 'lib/arcp/lease.rb', line 81

def initialize(capabilities:, budget: nil, model_use: nil, expires_at: nil)
  super(
    capabilities: Array(capabilities).freeze,
    budget: budget,
    model_use: model_use ? Array(model_use).freeze : nil,
    expires_at: expires_at
  )
end

Instance Attribute Details

#budgetObject (readonly)

Returns the value of attribute budget

Returns:

  • (Object)

    the current value of budget



80
81
82
# File 'lib/arcp/lease.rb', line 80

def budget
  @budget
end

#capabilitiesObject (readonly)

Returns the value of attribute capabilities

Returns:

  • (Object)

    the current value of capabilities



80
81
82
# File 'lib/arcp/lease.rb', line 80

def capabilities
  @capabilities
end

#expires_atObject (readonly)

Returns the value of attribute expires_at

Returns:

  • (Object)

    the current value of expires_at



80
81
82
# File 'lib/arcp/lease.rb', line 80

def expires_at
  @expires_at
end

#model_useObject (readonly)

Returns the value of attribute model_use

Returns:

  • (Object)

    the current value of model_use



80
81
82
# File 'lib/arcp/lease.rb', line 80

def model_use
  @model_use
end

Class Method Details

.from_h(h) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/arcp/lease.rb', line 90

def self.from_h(h)
  return nil if h.nil?

  h = h.transform_keys(&:to_s)
  new(
    capabilities: Array(h['capabilities']).freeze,
    budget: h['cost.budget'] ? CostBudget.parse(h['cost.budget']) : nil,
    model_use: h['model.use'] ? Array(h['model.use']).freeze : nil,
    expires_at: h['expires_at']
  )
end

Instance Method Details

#to_hObject



102
103
104
105
106
107
108
# File 'lib/arcp/lease.rb', line 102

def to_h
  out = { 'capabilities' => capabilities }
  out['cost.budget'] = budget.to_a if budget
  out['model.use'] = model_use if model_use
  out['expires_at'] = expires_at if expires_at
  out
end