Class: AdvancedBilling::CreateComponentPricePoint

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/create_component_price_point.rb

Overview

CreateComponentPricePoint Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(name = nil, pricing_scheme = nil, prices = nil, handle = SKIP, use_site_exchange_rate = true) ⇒ CreateComponentPricePoint

Returns a new instance of CreateComponentPricePoint.



57
58
59
60
61
62
63
64
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 57

def initialize(name = nil, pricing_scheme = nil, prices = nil,
               handle = SKIP, use_site_exchange_rate = true)
  @name = name
  @handle = handle unless handle == SKIP
  @pricing_scheme = pricing_scheme
  @prices = prices
  @use_site_exchange_rate = use_site_exchange_rate unless use_site_exchange_rate == SKIP
end

Instance Attribute Details

#handleString

TODO: Write general description for this method

Returns:

  • (String)


18
19
20
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 18

def handle
  @handle
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


14
15
16
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 14

def name
  @name
end

#pricesArray[Price]

TODO: Write general description for this method

Returns:



26
27
28
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 26

def prices
  @prices
end

#pricing_schemeString

TODO: Write general description for this method

Returns:

  • (String)


22
23
24
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 22

def pricing_scheme
  @pricing_scheme
end

#use_site_exchange_rateTrueClass | FalseClass

Whether to use the site level exchange rate or define your own prices for each currency if you have multiple currencies defined on the site.

Returns:

  • (TrueClass | FalseClass)


31
32
33
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 31

def use_site_exchange_rate
  @use_site_exchange_rate
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 67

def self.from_hash(hash)
  return nil unless hash

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

  prices = nil unless hash.key?('prices')
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  use_site_exchange_rate = hash['use_site_exchange_rate'] ||= true

  # Create object from extracted values.
  CreateComponentPricePoint.new(name,
                                pricing_scheme,
                                prices,
                                handle,
                                use_site_exchange_rate)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
42
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_hash['pricing_scheme'] = 'pricing_scheme'
  @_hash['prices'] = 'prices'
  @_hash['use_site_exchange_rate'] = 'use_site_exchange_rate'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



45
46
47
48
49
50
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 45

def self.optionals
  %w[
    handle
    use_site_exchange_rate
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/advanced_billing/models/create_component_price_point.rb', line 97

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.name,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.pricing_scheme,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.prices,
                              ->(val) { Price.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['name'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['pricing_scheme'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['prices'],
                            ->(val) { Price.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true)
  )
end