class Ec2spec::HostResult

Constants

LABEL_WITH_METHODS
MONTH_OF_DAYS
NA_VALUE
NUMBER_OF_DECIMAL_PLACES

Attributes

backend[RW]
host[RW]
instance_id[RW]
instance_type[R]
price_per_unit[W]
vcpu[W]

Public Class Methods

label_with_methods() click to toggle source
# File lib/ec2spec/host_result.rb, line 20
def self.label_with_methods
  label_methods = LABEL_WITH_METHODS
  if PriceCalculator.instance.currency_values?
    label_methods['price (%s/H)'] = :price_per_currency_unit
    label_methods['price (%s/M)'] = :price_per_currency_unit_month
  end
  label_methods
end
new(region, host, days = nil) click to toggle source
# File lib/ec2spec/host_result.rb, line 29
def initialize(region, host, days = nil)
  @region = region
  @host = host
  @backend = nil
  @days = days || MONTH_OF_DAYS
end

Public Instance Methods

instance_type=(value) click to toggle source
# File lib/ec2spec/host_result.rb, line 44
def instance_type=(value)
  @instance_type = value

  return if value == NA_VALUE
  price_per_unit
end
memory() click to toggle source
# File lib/ec2spec/host_result.rb, line 56
def memory
  @memory ||=
    Ec2spec::OfferFile.instance.memory(@instance_type)
end
na_values() click to toggle source
# File lib/ec2spec/host_result.rb, line 36
def na_values
  @instance_type = NA_VALUE
  @instance_id = NA_VALUE
  @memory = NA_VALUE
  @vcpu = NA_VALUE
  @price_per_unit = NA_VALUE
end
price_per_currency_unit() click to toggle source
# File lib/ec2spec/host_result.rb, line 66
def price_per_currency_unit
  return @price_per_currency_unit unless @price_per_currency_unit.nil?

  dollar_price = Ec2spec::OfferFile.instance.price_per_unit(@instance_type)
  @price_per_currency_unit = PriceCalculator
                             .instance.currency_unit_price(dollar_price)
  @price_per_currency_unit.fractional.floor(NUMBER_OF_DECIMAL_PLACES).to_f
end
price_per_currency_unit_month() click to toggle source
# File lib/ec2spec/host_result.rb, line 80
def price_per_currency_unit_month
  return NA_VALUE if @price_per_currency_unit == NA_VALUE
  (@price_per_currency_unit * 24 * @days)
    .fractional.floor(NUMBER_OF_DECIMAL_PLACES).to_f
end
price_per_month() click to toggle source
# File lib/ec2spec/host_result.rb, line 75
def price_per_month
  return NA_VALUE if @price_per_unit == NA_VALUE
  @price_per_unit * 24 * @days
end
price_per_unit() click to toggle source
# File lib/ec2spec/host_result.rb, line 61
def price_per_unit
  @price_per_unit ||=
    Ec2spec::OfferFile.instance.price_per_unit(@instance_type)
end
to_hash() click to toggle source
# File lib/ec2spec/host_result.rb, line 86
def to_hash
  host_values
end
vcpu() click to toggle source
# File lib/ec2spec/host_result.rb, line 51
def vcpu
  @vcpu ||=
    Ec2spec::OfferFile.instance.vcpu(@instance_type)
end

Private Instance Methods

host_values() click to toggle source
# File lib/ec2spec/host_result.rb, line 92
def host_values
  self.class.label_with_methods.each_with_object({}) do |(k, v), hash|
    unit = PriceCalculator.instance.currency_unit
    label = format(k, unit)
    hash[label] = public_send(v)
  end
end