Class: ShellEv::TariffElement

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

Overview

TariffElement 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(price_components = nil, restrictions = SKIP) ⇒ TariffElement

Returns a new instance of TariffElement.



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

def initialize(price_components = nil, restrictions = SKIP)
  @price_components = price_components
  @restrictions = restrictions unless restrictions == SKIP
end

Instance Attribute Details

#price_componentsArray[PriceComponent]

TODO: Write general description for this method

Returns:



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

def price_components
  @price_components
end

#restrictionsRestrictions

TODO: Write general description for this method

Returns:



18
19
20
# File 'lib/shell_ev/models/tariff_element.rb', line 18

def restrictions
  @restrictions
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/shell_ev/models/tariff_element.rb', line 46

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  price_components = nil
  unless hash['priceComponents'].nil?
    price_components = []
    hash['priceComponents'].each do |structure|
      price_components << (PriceComponent.from_hash(structure) if structure)
    end
  end

  price_components = nil unless hash.key?('priceComponents')
  restrictions = Restrictions.from_hash(hash['restrictions']) if hash['restrictions']

  # Create object from extracted values.
  TariffElement.new(price_components,
                    restrictions)
end

.namesObject

A mapping from model property names to API property names.



21
22
23
24
25
26
# File 'lib/shell_ev/models/tariff_element.rb', line 21

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['price_components'] = 'priceComponents'
  @_hash['restrictions'] = 'restrictions'
  @_hash
end

.nullablesObject

An array for nullable fields



36
37
38
# File 'lib/shell_ev/models/tariff_element.rb', line 36

def self.nullables
  []
end

.optionalsObject

An array for optional fields



29
30
31
32
33
# File 'lib/shell_ev/models/tariff_element.rb', line 29

def self.optionals
  %w[
    restrictions
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

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

#to_sObject

Provides a human-readable string representation of the object.



68
69
70
71
# File 'lib/shell_ev/models/tariff_element.rb', line 68

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} price_components: #{@price_components}, restrictions: #{@restrictions}>"
end