Class: IspUsage::Fetchers::Fetcher
- Inherits:
-
Object
- Object
- IspUsage::Fetchers::Fetcher
- Defined in:
- lib/ispusage/fetchers/fetcher.rb
Direct Known Subclasses
AUExetel, AUIinet, AUInternode, AUOptus, AUThree, AUTpg, AUTranslink
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#month_end ⇒ Object
Returns the value of attribute month_end.
-
#options ⇒ Object
Returns the value of attribute options.
-
#password ⇒ Object
Returns the value of attribute password.
-
#usage_periods ⇒ Object
Returns the value of attribute usage_periods.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(options) ⇒ Fetcher
constructor
A new instance of Fetcher.
- #month_used ⇒ Object
- #new_usage_period(options = {}) ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(options) ⇒ Fetcher
Returns a new instance of Fetcher.
9 10 11 12 13 14 15 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 9 def initialize() @username = [:username] @password = [:password] self. = self.month_end = [:month_end] self.usage_periods = [] end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
7 8 9 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 7 def error @error end |
#month_end ⇒ Object
Returns the value of attribute month_end.
7 8 9 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 7 def month_end @month_end end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 7 def @options end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 7 def password @password end |
#usage_periods ⇒ Object
Returns the value of attribute usage_periods.
7 8 9 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 7 def usage_periods @usage_periods end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 7 def username @username end |
Instance Method Details
#month_used ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 40 def month_used return nil if month_end.nil? month_start = Time.local(month_end.year, month_end.month - 1, month_end.day) month_length = month_end.to_f - month_start.to_f (1 - (month_end.to_f - Time.now.to_f) / month_length.to_f) * 100 end |
#new_usage_period(options = {}) ⇒ Object
49 50 51 52 53 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 49 def new_usage_period( = {}) usage_period = IspUsage::UsagePeriod.new(self, ) self.usage_periods << usage_period usage_period end |
#to_hash ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 17 def to_hash hash = { :isp => self.class.to_s.split('::').last, :username => @username, :usage_periods => self.usage_periods.map(&:to_hash) } unless month_end.nil? hash[:month_end] = month_end hash[:month_used] = month_used end unless error.nil? hash[:error] = error end hash end |
#to_json ⇒ Object
36 37 38 |
# File 'lib/ispusage/fetchers/fetcher.rb', line 36 def to_json to_hash.to_json end |