Class: AWSCosts::S3Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/awscosts/s3_storage.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ S3Storage

Returns a new instance of S3Storage.



5
6
7
# File 'lib/awscosts/s3_storage.rb', line 5

def initialize data
  @data = data
end

Class Method Details

.fetch(region) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/awscosts/s3_storage.rb', line 13

def self.fetch region
  transformed = AWSCosts::Cache.get_jsonp("/pricing/1/s3/pricing-storage-s3.min.js") do |data|
    result = {}
    data['config']['regions'].each do |r|
      tiers = {}
      r['tiers'].each do |tier|
        storage_type = {}
        tiers[tier['name']] = storage_type
        tier['storageTypes'].each do |type|
          # Don't return 0.0 for "N/A*" since that is misleading
          storage_type[type['type']] = type['prices']['USD'] == 'N/A*' ? nil : type['prices']['USD'].to_f
        end
      end
      result[r['region']] = tiers
    end
    result
  end
  self.new(transformed[region])
end

Instance Method Details

#price(tier = nil) ⇒ Object



9
10
11
# File 'lib/awscosts/s3_storage.rb', line 9

def price tier = nil
  tier.nil? ? @data : @data[tier.to_s]
end