Class: IspUsage::UsagePeriod
- Inherits:
-
Object
- Object
- IspUsage::UsagePeriod
- Defined in:
- lib/ispusage/usage_period.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
Returns the value of attribute label.
-
#quota ⇒ Object
Returns the value of attribute quota.
-
#type ⇒ Object
Returns the value of attribute type.
-
#used ⇒ Object
Returns the value of attribute used.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ UsagePeriod
constructor
A new instance of UsagePeriod.
- #to_hash ⇒ Object
- #total ⇒ Object
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( = {}) self.label = 'No Label Set' self.type = :meter auto_setters = [:quota, :used, :label, :type] .each do |key, value| if auto_setters.include?(key) self.send(key.to_s + '=', value) end end end |
Instance Attribute Details
#label ⇒ Object
Returns the value of attribute label.
3 4 5 |
# File 'lib/ispusage/usage_period.rb', line 3 def label @label end |
#quota ⇒ Object
Returns the value of attribute quota.
3 4 5 |
# File 'lib/ispusage/usage_period.rb', line 3 def quota @quota end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/ispusage/usage_period.rb', line 4 def type @type end |
#used ⇒ Object
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_hash ⇒ Object
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 |
#total ⇒ Object
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 |