Class: Ec2spec::HostResult

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2spec/host_result.rb

Constant Summary collapse

MONTH_OF_DAYS =
31
NA_VALUE =
'N/A'
NUMBER_OF_DECIMAL_PLACES =
3
LABEL_WITH_METHODS =
{
  'instance_type' => :instance_type,
  'instance_id'   => :instance_id,
  'vCPU'          => :vcpu,
  'memory'        => :memory,
  'price (USD/H)' => :price_per_unit,
  'price (USD/M)' => :price_per_month,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, host, days = nil) ⇒ HostResult

Returns a new instance of HostResult.



29
30
31
32
33
34
# 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

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



16
17
18
# File 'lib/ec2spec/host_result.rb', line 16

def backend
  @backend
end

#hostObject

Returns the value of attribute host.



16
17
18
# File 'lib/ec2spec/host_result.rb', line 16

def host
  @host
end

#instance_idObject

Returns the value of attribute instance_id.



16
17
18
# File 'lib/ec2spec/host_result.rb', line 16

def instance_id
  @instance_id
end

#instance_typeObject

Returns the value of attribute instance_type.



17
18
19
# File 'lib/ec2spec/host_result.rb', line 17

def instance_type
  @instance_type
end

#price_per_unitObject



61
62
63
64
# File 'lib/ec2spec/host_result.rb', line 61

def price_per_unit
  @price_per_unit ||=
    Ec2spec::OfferFile.instance.price_per_unit(@instance_type)
end

#vcpuObject



51
52
53
54
# File 'lib/ec2spec/host_result.rb', line 51

def vcpu
  @vcpu ||=
    Ec2spec::OfferFile.instance.vcpu(@instance_type)
end

Class Method Details

.label_with_methodsObject



20
21
22
23
24
25
26
27
# 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

Instance Method Details

#memoryObject



56
57
58
59
# File 'lib/ec2spec/host_result.rb', line 56

def memory
  @memory ||=
    Ec2spec::OfferFile.instance.memory(@instance_type)
end

#na_valuesObject



36
37
38
39
40
41
42
# 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_unitObject



66
67
68
69
70
71
72
73
# 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_monthObject



80
81
82
83
84
# 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_monthObject



75
76
77
78
# 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

#to_hashObject



86
87
88
# File 'lib/ec2spec/host_result.rb', line 86

def to_hash
  host_values
end