Class: ShellEv::PriceComponent

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/shell_ev/models/price_component.rb

Overview

PriceComponent Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(type = nil, step_size = nil, price = nil, vat = nil) ⇒ PriceComponent

Returns a new instance of PriceComponent.



49
50
51
52
53
54
# File 'lib/shell_ev/models/price_component.rb', line 49

def initialize(type = nil, step_size = nil, price = nil, vat = nil)
  @type = type
  @step_size = step_size
  @price = price
  @vat = vat
end

Instance Attribute Details

#priceFloat

Price per step in the specified currency for this price component

Returns:

  • (Float)


23
24
25
# File 'lib/shell_ev/models/price_component.rb', line 23

def price
  @price
end

#step_sizeInteger

Step size in seconds for TIME-based components, in kWh for ENERGY-based components, or 1 for FLAT components

Returns:

  • (Integer)


19
20
21
# File 'lib/shell_ev/models/price_component.rb', line 19

def step_size
  @step_size
end

#typeTypeEnum

Type of the price component

Returns:



14
15
16
# File 'lib/shell_ev/models/price_component.rb', line 14

def type
  @type
end

#vatFloat

VAT percentage applicable to this price component

Returns:

  • (Float)


27
28
29
# File 'lib/shell_ev/models/price_component.rb', line 27

def vat
  @vat
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/shell_ev/models/price_component.rb', line 57

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  type = hash.key?('type') ? hash['type'] : nil
  step_size = hash.key?('stepSize') ? hash['stepSize'] : nil
  price = hash.key?('price') ? hash['price'] : nil
  vat = hash.key?('vat') ? hash['vat'] : nil

  # Create object from extracted values.
  PriceComponent.new(type,
                     step_size,
                     price,
                     vat)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/shell_ev/models/price_component.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['type'] = 'type'
  @_hash['step_size'] = 'stepSize'
  @_hash['price'] = 'price'
  @_hash['vat'] = 'vat'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/shell_ev/models/price_component.rb', line 45

def self.nullables
  []
end

.optionalsObject

An array for optional fields



40
41
42
# File 'lib/shell_ev/models/price_component.rb', line 40

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



80
81
82
83
84
# File 'lib/shell_ev/models/price_component.rb', line 80

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} type: #{@type.inspect}, step_size: #{@step_size.inspect}, price:"\
  " #{@price.inspect}, vat: #{@vat.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



74
75
76
77
# File 'lib/shell_ev/models/price_component.rb', line 74

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} type: #{@type}, step_size: #{@step_size}, price: #{@price}, vat: #{@vat}>"
end