Class: AwsPricing::CategoryType

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon-pricing/definitions/category-type.rb

Direct Known Subclasses

Cache, DatabaseType, OperatingSystem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance_type = nil, name = nil) ⇒ CategoryType

Returns a new instance of CategoryType.



47
48
49
50
# File 'lib/amazon-pricing/definitions/category-type.rb', line 47

def initialize(instance_type=nil, name=nil)
  @instance_type = instance_type
  @name = name
end

Instance Attribute Details

#allupfront_prepay_1_yearObject

Returns the value of attribute allupfront_prepay_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def allupfront_prepay_1_year
  @allupfront_prepay_1_year
end

#allupfront_prepay_3_yearObject

Returns the value of attribute allupfront_prepay_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def allupfront_prepay_3_year
  @allupfront_prepay_3_year
end

#convertible_allupfront_prepay_1_yearObject

Returns the value of attribute convertible_allupfront_prepay_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_allupfront_prepay_1_year
  @convertible_allupfront_prepay_1_year
end

#convertible_allupfront_prepay_3_yearObject

Returns the value of attribute convertible_allupfront_prepay_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_allupfront_prepay_3_year
  @convertible_allupfront_prepay_3_year
end

#convertible_noupfront_price_per_hour_1_yearObject

Returns the value of attribute convertible_noupfront_price_per_hour_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_noupfront_price_per_hour_1_year
  @convertible_noupfront_price_per_hour_1_year
end

#convertible_noupfront_price_per_hour_3_yearObject

Returns the value of attribute convertible_noupfront_price_per_hour_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_noupfront_price_per_hour_3_year
  @convertible_noupfront_price_per_hour_3_year
end

#convertible_partialupfront_prepay_1_yearObject

Returns the value of attribute convertible_partialupfront_prepay_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_partialupfront_prepay_1_year
  @convertible_partialupfront_prepay_1_year
end

#convertible_partialupfront_prepay_3_yearObject

Returns the value of attribute convertible_partialupfront_prepay_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_partialupfront_prepay_3_year
  @convertible_partialupfront_prepay_3_year
end

#convertible_partialupfront_price_per_hour_1_yearObject

Returns the value of attribute convertible_partialupfront_price_per_hour_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_partialupfront_price_per_hour_1_year
  @convertible_partialupfront_price_per_hour_1_year
end

#convertible_partialupfront_price_per_hour_3_yearObject

Returns the value of attribute convertible_partialupfront_price_per_hour_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def convertible_partialupfront_price_per_hour_3_year
  @convertible_partialupfront_price_per_hour_3_year
end

#heavy_prepay_1_yearObject

Returns the value of attribute heavy_prepay_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def heavy_prepay_1_year
  @heavy_prepay_1_year
end

#heavy_prepay_3_yearObject

Returns the value of attribute heavy_prepay_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def heavy_prepay_3_year
  @heavy_prepay_3_year
end

#heavy_price_per_hour_1_yearObject

Returns the value of attribute heavy_price_per_hour_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def heavy_price_per_hour_1_year
  @heavy_price_per_hour_1_year
end

#heavy_price_per_hour_3_yearObject

Returns the value of attribute heavy_price_per_hour_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def heavy_price_per_hour_3_year
  @heavy_price_per_hour_3_year
end

#instance_typeObject

Returns the value of attribute instance_type.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def instance_type
  @instance_type
end

#light_prepay_1_yearObject

Returns the value of attribute light_prepay_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def light_prepay_1_year
  @light_prepay_1_year
end

#light_prepay_3_yearObject

Returns the value of attribute light_prepay_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def light_prepay_3_year
  @light_prepay_3_year
end

#light_price_per_hour_1_yearObject

Returns the value of attribute light_price_per_hour_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def light_price_per_hour_1_year
  @light_price_per_hour_1_year
end

#light_price_per_hour_3_yearObject

Returns the value of attribute light_price_per_hour_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def light_price_per_hour_3_year
  @light_price_per_hour_3_year
end

#medium_prepay_1_yearObject

Returns the value of attribute medium_prepay_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def medium_prepay_1_year
  @medium_prepay_1_year
end

#medium_prepay_3_yearObject

Returns the value of attribute medium_prepay_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def medium_prepay_3_year
  @medium_prepay_3_year
end

#medium_price_per_hour_1_yearObject

Returns the value of attribute medium_price_per_hour_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def medium_price_per_hour_1_year
  @medium_price_per_hour_1_year
end

#medium_price_per_hour_3_yearObject

Returns the value of attribute medium_price_per_hour_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def medium_price_per_hour_3_year
  @medium_price_per_hour_3_year
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def name
  @name
end

#noupfront_price_per_hour_1_yearObject

Returns the value of attribute noupfront_price_per_hour_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def noupfront_price_per_hour_1_year
  @noupfront_price_per_hour_1_year
end

#noupfront_price_per_hour_3_yearObject

Returns the value of attribute noupfront_price_per_hour_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def noupfront_price_per_hour_3_year
  @noupfront_price_per_hour_3_year
end

#ondemand_price_per_hourObject

Returns the value of attribute ondemand_price_per_hour.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def ondemand_price_per_hour
  @ondemand_price_per_hour
end

#partialupfront_prepay_1_yearObject

Returns the value of attribute partialupfront_prepay_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def partialupfront_prepay_1_year
  @partialupfront_prepay_1_year
end

#partialupfront_prepay_3_yearObject

Returns the value of attribute partialupfront_prepay_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def partialupfront_prepay_3_year
  @partialupfront_prepay_3_year
end

#partialupfront_price_per_hour_1_yearObject

Returns the value of attribute partialupfront_price_per_hour_1_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def partialupfront_price_per_hour_1_year
  @partialupfront_price_per_hour_1_year
end

#partialupfront_price_per_hour_3_yearObject

Returns the value of attribute partialupfront_price_per_hour_3_year.



13
14
15
# File 'lib/amazon-pricing/definitions/category-type.rb', line 13

def partialupfront_price_per_hour_3_year
  @partialupfront_price_per_hour_3_year
end

Instance Method Details

#allupfront_effective_rate_1_yearObject



27
28
29
# File 'lib/amazon-pricing/definitions/category-type.rb', line 27

def allupfront_effective_rate_1_year
  (allupfront_prepay_1_year / 365 / 24).round(4)
end

#allupfront_effective_rate_3_yearObject



31
32
33
# File 'lib/amazon-pricing/definitions/category-type.rb', line 31

def allupfront_effective_rate_3_year
  (allupfront_prepay_3_year / 3 / 365 / 24).round(4)
end

#available?(type_of_instance = :ondemand) ⇒ Boolean

Returns whether an instance_type is available. type_of_instance = :ondemand, :light, :medium, :heavy

Returns:

  • (Boolean)


54
55
56
# File 'lib/amazon-pricing/definitions/category-type.rb', line 54

def available?(type_of_instance = :ondemand)
  not price_per_hour(type_of_instance).nil?
end

#get_breakeven_month(type_of_instance, term) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil



250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/amazon-pricing/definitions/category-type.rb', line 250

def get_breakeven_month(type_of_instance, term)
  # Some regions and types do not have reserved available
  ondemand_pph = price_per_hour(:ondemand)
  reserved_pph = price_per_hour(type_of_instance, term)
  return nil if ondemand_pph.nil? || reserved_pph.nil?

  on_demand = 0
  reserved = prepay(type_of_instance, term)
  return nil if reserved.nil?

  for i in 1..36 do
    on_demand +=  ondemand_pph * 24 * 30.4 
    reserved += reserved_pph * 24 * 30.4 
    return i if reserved < on_demand
  end
  nil
end

#noupfront_effective_rate_1_yearObject



43
44
45
# File 'lib/amazon-pricing/definitions/category-type.rb', line 43

def noupfront_effective_rate_1_year
  (noupfront_price_per_hour_1_year).round(4)
end

#partialupfront_effective_rate_1_yearObject



35
36
37
# File 'lib/amazon-pricing/definitions/category-type.rb', line 35

def partialupfront_effective_rate_1_year
  (partialupfront_prepay_1_year / 365 / 24 + partialupfront_price_per_hour_1_year).round(4)
end

#partialupfront_effective_rate_3_yearObject



39
40
41
# File 'lib/amazon-pricing/definitions/category-type.rb', line 39

def partialupfront_effective_rate_3_year
  (partialupfront_prepay_3_year / 3 / 365 / 24 + partialupfront_price_per_hour_3_year).round(4)
end

#prepay(type_of_instance = :ondemand, term = nil) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil



60
61
62
63
64
65
66
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
94
95
96
97
98
99
100
101
102
103
# File 'lib/amazon-pricing/definitions/category-type.rb', line 60

def prepay(type_of_instance = :ondemand, term = nil)
  case type_of_instance
  when :ondemand
    0
  when :light
    if term == :year1
      @light_prepay_1_year
    elsif term == :year3
      @light_prepay_3_year
    end
  when :medium
    if term == :year1
      @medium_prepay_1_year
    elsif term == :year3
      @medium_prepay_3_year
    end
  when :heavy
    if term == :year1
      @heavy_prepay_1_year
    elsif term == :year3
      @heavy_prepay_3_year
    end
  when :allupfront
    if term == :year1
      @allupfront_prepay_1_year
    elsif term == :year1_convertible
      @convertible_allupfront_prepay_1_year
    elsif term == :year3
      @allupfront_prepay_3_year
    elsif term == :year3_convertible
      @convertible_allupfront_prepay_3_year
    end
  when :partialupfront
    if term == :year1
      @partialupfront_prepay_1_year
    elsif term == :year1_convertible
      @convertible_partialupfront_prepay_1_year
    elsif term == :year3
      @partialupfront_prepay_3_year
    elsif term == :year3_convertible
      @convertible_partialupfront_prepay_3_year
    end
  end
end

#price_per_hour(type_of_instance = :ondemand, term = nil) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year1, :year3, nil



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/amazon-pricing/definitions/category-type.rb', line 154

def price_per_hour(type_of_instance = :ondemand, term = nil)
  case type_of_instance
  when :ondemand
    @ondemand_price_per_hour
  when :light
    if term == :year1
      @light_price_per_hour_1_year
    elsif term == :year3
      @light_price_per_hour_3_year
    end
  when :medium
    if term == :year1
      @medium_price_per_hour_1_year
    elsif term == :year3
      @medium_price_per_hour_3_year
    end
  when :heavy
    if term == :year1
      @heavy_price_per_hour_1_year
    elsif term == :year3
      @heavy_price_per_hour_3_year
    end
  when :partialupfront
    if term == :year1
      @partialupfront_price_per_hour_1_year
    elsif term == :year1_convertible
      @convertible_partialupfront_price_per_hour_1_year
    elsif term == :year3
      @partialupfront_price_per_hour_3_year
    elsif term == :year3_convertible
      @convertible_partialupfront_price_per_hour_3_year
    end
  when :noupfront
    if term == :year1
      @noupfront_price_per_hour_1_year
    elsif term == :year1_convertible
      @convertible_noupfront_price_per_hour_1_year
    elsif term == :year3
      @noupfront_price_per_hour_3_year
    elsif term == :year3_convertible
      @convertible_noupfront_price_per_hour_3_year
    end
  when :allupfront
    0
  end
end

#set_prepay(type_of_instance, term, price) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year1, :year3, nil



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/amazon-pricing/definitions/category-type.rb', line 107

def set_prepay(type_of_instance, term, price)
  case type_of_instance
  when :light
    if term == :year1
      @light_prepay_1_year = price
    elsif term == :year3
      @light_prepay_3_year = price
    end
  when :medium
    if term == :year1
      @medium_prepay_1_year = price
    elsif term == :year3
      @medium_prepay_3_year = price
    end
  when :heavy
    if term == :year1
      @heavy_prepay_1_year = price
    elsif term == :year3
      @heavy_prepay_3_year = price
    end
  when :allupfront
    if term == :year1
      @allupfront_prepay_1_year = price
    elsif term == :year1_convertible
      @convertible_allupfront_prepay_1_year = price
    elsif term == :year3
      @allupfront_prepay_3_year = price
    elsif term == :year3_convertible
      @convertible_allupfront_prepay_3_year = price
    end
  when :partialupfront
    if term == :year1
      @partialupfront_prepay_1_year = price
    elsif term == :year1_convertible
      @convertible_partialupfront_prepay_1_year = price
    elsif term == :year3
      @partialupfront_prepay_3_year = price
    elsif term == :year3_convertible
      @convertible_partialupfront_prepay_3_year = price
    end
  else
    raise "Unable to set prepay for #{instance_type.api_name} : #{name} : #{type_of_instance} : #{term} to #{price}"
  end
end

#set_price_per_hour(type_of_instance, term, price_per_hour) ⇒ Object

type_of_instance = :ondemand, :light, :medium, :heavy term = :year_1, :year_3, nil



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/amazon-pricing/definitions/category-type.rb', line 203

def set_price_per_hour(type_of_instance, term, price_per_hour)
  case type_of_instance
  when :ondemand
    @ondemand_price_per_hour = price_per_hour
  when :light
    if term == :year1
      @light_price_per_hour_1_year = price_per_hour
    elsif term == :year3
      @light_price_per_hour_3_year = price_per_hour
    end
  when :medium
    if term == :year1
      @medium_price_per_hour_1_year = price_per_hour
    elsif term == :year3
      @medium_price_per_hour_3_year = price_per_hour
    end
  when :heavy
    if term == :year1
      @heavy_price_per_hour_1_year = price_per_hour
    elsif term == :year3
      @heavy_price_per_hour_3_year = price_per_hour
    end
  when :partialupfront
    if term == :year1
      @partialupfront_price_per_hour_1_year = price_per_hour
    elsif term == :year1_convertible
      @convertible_partialupfront_price_per_hour_1_year = price_per_hour
    elsif term == :year3
      @partialupfront_price_per_hour_3_year = price_per_hour
    elsif term == :year3_convertible
      @convertible_partialupfront_price_per_hour_3_year = price_per_hour
    end
  when :noupfront
    if term == :year1
      @noupfront_price_per_hour_1_year = price_per_hour
    elsif term == :year1_convertible
      @convertible_noupfront_price_per_hour_1_year = price_per_hour
    elsif term == :year3
      @noupfront_price_per_hour_3_year = price_per_hour
    elsif term == :year3_convertible
      @convertible_noupfront_price_per_hour_3_year = price_per_hour
    end
  end
end