Class: ApiReference::UsageDiscountInterval
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- ApiReference::UsageDiscountInterval
- Defined in:
- lib/api_reference/models/usage_discount_interval.rb
Overview
UsageDiscountInterval Model.
Instance Attribute Summary collapse
-
#applies_to_price_interval_ids ⇒ Array[String]
The price interval ids that this discount interval applies to.
-
#discount_type ⇒ String
readonly
TODO: Write general description for this method.
-
#end_date ⇒ DateTime
The end date of the discount interval.
-
#filters ⇒ Array[PriceFilter]
The filters that determine which prices this discount interval applies to.
-
#start_date ⇒ DateTime
The start date of the discount interval.
-
#usage_discount ⇒ Float
Only available if discount_type is
usage.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
-
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
Instance Method Summary collapse
-
#initialize(usage_discount:, start_date:, end_date:, filters:, applies_to_price_interval_ids:, additional_properties: nil) ⇒ UsageDiscountInterval
constructor
A new instance of UsageDiscountInterval.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
- #to_custom_end_date ⇒ Object
- #to_custom_start_date ⇒ Object
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(usage_discount:, start_date:, end_date:, filters:, applies_to_price_interval_ids:, additional_properties: nil) ⇒ UsageDiscountInterval
Returns a new instance of UsageDiscountInterval.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 63 def initialize(usage_discount:, start_date:, end_date:, filters:, applies_to_price_interval_ids:, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @discount_type = 'usage' @usage_discount = usage_discount @start_date = start_date @end_date = end_date @filters = filters @applies_to_price_interval_ids = applies_to_price_interval_ids @additional_properties = additional_properties end |
Instance Attribute Details
#applies_to_price_interval_ids ⇒ Array[String]
The price interval ids that this discount interval applies to.
36 37 38 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 36 def applies_to_price_interval_ids @applies_to_price_interval_ids end |
#discount_type ⇒ String (readonly)
TODO: Write general description for this method
15 16 17 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 15 def discount_type @discount_type end |
#end_date ⇒ DateTime
The end date of the discount interval.
28 29 30 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 28 def end_date @end_date end |
#filters ⇒ Array[PriceFilter]
The filters that determine which prices this discount interval applies to.
32 33 34 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 32 def filters @filters end |
#start_date ⇒ DateTime
The start date of the discount interval.
24 25 26 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 24 def start_date @start_date end |
#usage_discount ⇒ Float
Only available if discount_type is usage. Number of usage units that
this discount is for
20 21 22 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 20 def usage_discount @usage_discount end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 78 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. usage_discount = hash.key?('usage_discount') ? hash['usage_discount'] : nil start_date = if hash.key?('start_date') (DateTimeHelper.from_rfc3339(hash['start_date']) if hash['start_date']) end end_date = if hash.key?('end_date') (DateTimeHelper.from_rfc3339(hash['end_date']) if hash['end_date']) end # Parameter is an array, so we need to iterate through it filters = nil unless hash['filters'].nil? filters = [] hash['filters'].each do |structure| filters << (PriceFilter.from_hash(structure) if structure) end end filters = nil unless hash.key?('filters') applies_to_price_interval_ids = hash.key?('applies_to_price_interval_ids') ? hash['applies_to_price_interval_ids'] : nil # Create a new hash for additional properties, removing known properties. new_hash = hash.reject { |k, _| names.value?(k) } additional_properties = APIHelper.get_additional_properties( new_hash, proc { |value| value } ) # Create object from extracted values. UsageDiscountInterval.new(usage_discount: usage_discount, start_date: start_date, end_date: end_date, filters: filters, applies_to_price_interval_ids: applies_to_price_interval_ids, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 39 def self.names @_hash = {} if @_hash.nil? @_hash['discount_type'] = 'discount_type' @_hash['usage_discount'] = 'usage_discount' @_hash['start_date'] = 'start_date' @_hash['end_date'] = 'end_date' @_hash['filters'] = 'filters' @_hash['applies_to_price_interval_ids'] = 'applies_to_price_interval_ids' @_hash end |
.nullables ⇒ Object
An array for nullable fields
57 58 59 60 61 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 57 def self.nullables %w[ end_date ] end |
.optionals ⇒ Object
An array for optional fields
52 53 54 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 52 def self.optionals [] end |
.validate(value) ⇒ Object
Validates an instance of the object from a given value.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 129 def self.validate(value) if value.instance_of? self return ( APIHelper.valid_type?(value.discount_type, ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value.usage_discount, ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value.start_date, ->(val) { val.instance_of? DateTime }) and APIHelper.valid_type?(value.end_date, ->(val) { val.instance_of? DateTime }) and APIHelper.valid_type?(value.filters, ->(val) { PriceFilter.validate(val) }, is_model_hash: true, is_inner_model_hash: true) and APIHelper.valid_type?(value.applies_to_price_interval_ids, ->(val) { val.instance_of? String }) ) end return false unless value.instance_of? Hash ( APIHelper.valid_type?(value['discount_type'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['usage_discount'], ->(val) { val.instance_of? Float }) and APIHelper.valid_type?(value['start_date'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['end_date'], ->(val) { val.instance_of? String }) and APIHelper.valid_type?(value['filters'], ->(val) { PriceFilter.validate(val) }, is_model_hash: true, is_inner_model_hash: true) and APIHelper.valid_type?(value['applies_to_price_interval_ids'], ->(val) { val.instance_of? String }) ) end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
179 180 181 182 183 184 185 186 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 179 def inspect class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type.inspect}, usage_discount:"\ " #{@usage_discount.inspect}, start_date: #{@start_date.inspect}, end_date:"\ " #{@end_date.inspect}, filters: #{@filters.inspect}, applies_to_price_interval_ids:"\ " #{@applies_to_price_interval_ids.inspect}, additional_properties:"\ " #{@additional_properties}>" end |
#to_custom_end_date ⇒ Object
123 124 125 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 123 def to_custom_end_date DateTimeHelper.to_rfc3339(end_date) end |
#to_custom_start_date ⇒ Object
119 120 121 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 119 def to_custom_start_date DateTimeHelper.to_rfc3339(start_date) end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
170 171 172 173 174 175 176 |
# File 'lib/api_reference/models/usage_discount_interval.rb', line 170 def to_s class_name = self.class.name.split('::').last "<#{class_name} discount_type: #{@discount_type}, usage_discount: #{@usage_discount},"\ " start_date: #{@start_date}, end_date: #{@end_date}, filters: #{@filters},"\ " applies_to_price_interval_ids: #{@applies_to_price_interval_ids}, additional_properties:"\ " #{@additional_properties}>" end |