Class: Heathrow::Source
- Inherits:
-
Object
- Object
- Heathrow::Source
- Defined in:
- lib/heathrow/source.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_poll ⇒ Object
Returns the value of attribute last_poll.
-
#name ⇒ Object
Returns the value of attribute name.
-
#poll_interval ⇒ Object
Returns the value of attribute poll_interval.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #generate_id ⇒ Object
-
#initialize(attrs = {}) ⇒ Source
constructor
A new instance of Source.
- #should_poll? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Source
Returns a new instance of Source.
6 7 8 9 10 11 12 13 14 |
# File 'lib/heathrow/source.rb', line 6 def initialize(attrs = {}) @id = attrs[:id] || generate_id @type = attrs[:type] @name = attrs[:name] @config = attrs[:config] || {} @enabled = attrs[:enabled] != false @poll_interval = attrs[:poll_interval] || 60 @last_poll = attrs[:last_poll] end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/heathrow/source.rb', line 4 def config @config end |
#enabled ⇒ Object
Returns the value of attribute enabled.
4 5 6 |
# File 'lib/heathrow/source.rb', line 4 def enabled @enabled end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/heathrow/source.rb', line 4 def id @id end |
#last_poll ⇒ Object
Returns the value of attribute last_poll.
4 5 6 |
# File 'lib/heathrow/source.rb', line 4 def last_poll @last_poll end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/heathrow/source.rb', line 4 def name @name end |
#poll_interval ⇒ Object
Returns the value of attribute poll_interval.
4 5 6 |
# File 'lib/heathrow/source.rb', line 4 def poll_interval @poll_interval end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/heathrow/source.rb', line 4 def type @type end |
Instance Method Details
#generate_id ⇒ Object
16 17 18 |
# File 'lib/heathrow/source.rb', line 16 def generate_id "#{@type}_#{Time.now.to_i}_#{rand(1000)}" end |
#should_poll? ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/heathrow/source.rb', line 32 def should_poll? return false unless @enabled return true if @last_poll.nil? Time.now - Time.parse(@last_poll) >= @poll_interval end |
#to_h ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/heathrow/source.rb', line 20 def to_h { id: @id, type: @type, name: @name, config: @config.to_json, enabled: @enabled ? 1 : 0, poll_interval: @poll_interval, last_poll: @last_poll } end |