Class: AwsPricing::CategoryType

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

Direct Known Subclasses

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


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

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/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/category-type.rb', line 13

def allupfront_prepay_3_year
  @allupfront_prepay_3_year
end

#heavy_prepay_1_yearObject

Returns the value of attribute heavy_prepay_1_year


13
14
15
# File 'lib/amazon-pricing/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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


21
22
23
# File 'lib/amazon-pricing/category-type.rb', line 21

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

#allupfront_effective_rate_3_yearObject


25
26
27
# File 'lib/amazon-pricing/category-type.rb', line 25

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)

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

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


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/amazon-pricing/category-type.rb', line 210

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


37
38
39
# File 'lib/amazon-pricing/category-type.rb', line 37

def noupfront_effective_rate_1_year
  (noupfront_price_per_hour_1_year).round(4)
end

#partialupfront_effective_rate_1_yearObject


29
30
31
# File 'lib/amazon-pricing/category-type.rb', line 29

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


33
34
35
# File 'lib/amazon-pricing/category-type.rb', line 33

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


54
55
56
57
58
59
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
# File 'lib/amazon-pricing/category-type.rb', line 54

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 == :year3
      @allupfront_prepay_3_year
    end
  when :partialupfront
    if term == :year1
      @partialupfront_prepay_1_year
    elsif term == :year3
      @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


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/amazon-pricing/category-type.rb', line 132

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 == :year3
      @partialupfront_price_per_hour_3_year
    end
  when :noupfront
    if term == :year1
      @noupfront_price_per_hour_1_year
    elsif term == :year3
      @noupfront_price_per_hour_3_year
    end
  end
end

#set_prepay(type_of_instance, term, price) ⇒ Object

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


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
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/amazon-pricing/category-type.rb', line 93

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 == :year3
      @allupfront_prepay_3_year = price
    end
  when :partialupfront
    if term == :year1
      @partialupfront_prepay_1_year = price
    elsif term == :year3
      @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


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
200
201
202
203
204
205
206
# File 'lib/amazon-pricing/category-type.rb', line 171

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 == :year3
      @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 == :year3
      @noupfront_price_per_hour_3_year = price_per_hour
    end
  end
end