Class: IspUsage::UsagePeriod

Inherits:
Object
  • Object
show all
Defined in:
lib/ispusage/usage_period.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fetcher, options = {}) ⇒ UsagePeriod

Returns a new instance of UsagePeriod.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/ispusage/usage_period.rb', line 5

def initialize(fetcher, options = {})
  self.fetcher = fetcher
  self.type = :meter
  self.label = ''
  auto_setters = [:quota, :used, :label, :type]
  options.each do |key, value|
    if auto_setters.include?(key)
      self.send(key.to_s + '=', value)
    end
  end
end

Instance Attribute Details

#fetcherObject

Returns the value of attribute fetcher.



3
4
5
# File 'lib/ispusage/usage_period.rb', line 3

def fetcher
  @fetcher
end

#labelObject

Returns the value of attribute label.



3
4
5
# File 'lib/ispusage/usage_period.rb', line 3

def label
  @label
end

#quotaObject

Returns the value of attribute quota.



3
4
5
# File 'lib/ispusage/usage_period.rb', line 3

def quota
  @quota
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/ispusage/usage_period.rb', line 4

def type
  @type
end

#usedObject

Returns the value of attribute used.



3
4
5
# File 'lib/ispusage/usage_period.rb', line 3

def used
  @used
end

Instance Method Details

#month_megabytes_usedObject



52
53
54
55
# File 'lib/ispusage/usage_period.rb', line 52

def month_megabytes_used
  return nil if fetcher.month_used.nil?
  fetcher.month_used / 100 * quota
end

#to_hashObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ispusage/usage_period.rb', line 26

def to_hash
  hash = {
    :used => used,
    :label => label,
    :type => type
  }

  if type == :meter
    hash.merge!({
            :quota => quota,
            :total => total
    })
    hash[:month_megabytes_used] = month_megabytes_used if month_megabytes_used
  end
  
  hash
end

#totalObject



17
18
19
20
21
22
23
24
# File 'lib/ispusage/usage_period.rb', line 17

def total
  return nil if quota.nil? || used.nil?
  if quota > used
    return quota
  else
    return used
  end
end