Class: IspUsage::UsagePeriod
- Inherits:
-
Object
- Object
- IspUsage::UsagePeriod
- Defined in:
- lib/ispusage/usage_period.rb
Instance Attribute Summary collapse
-
#fetcher ⇒ Object
Returns the value of attribute fetcher.
-
#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(fetcher, options = {}) ⇒ UsagePeriod
constructor
A new instance of UsagePeriod.
- #month_megabytes_used ⇒ Object
- #to_hash ⇒ Object
- #total ⇒ Object
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, = {}) self.fetcher = fetcher self.type = :meter self.label = '' 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
#fetcher ⇒ Object
Returns the value of attribute fetcher.
3 4 5 |
# File 'lib/ispusage/usage_period.rb', line 3 def fetcher @fetcher end |
#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
#month_megabytes_used ⇒ Object
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_hash ⇒ Object
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 |
#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 |