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(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(options = {})
  self.label = 'No Label Set'
  self.type = :meter
  
  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

#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

#to_hashObject



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

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

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

  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