Class: Reportier::Tracker
- Inherits:
-
Object
- Object
- Reportier::Tracker
- Defined in:
- lib/reportier/tracker.rb
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#persister ⇒ Object
readonly
Returns the value of attribute persister.
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #add(item) ⇒ Object
-
#initialize(opts = {}) ⇒ Tracker
constructor
A new instance of Tracker.
- #report ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Tracker
Returns a new instance of Tracker.
12 13 14 15 16 17 18 19 20 |
# File 'lib/reportier/tracker.rb', line 12 def initialize(opts = {}) @defaults = Defaults.new @type = opts[:type] @reporter = opts[:reporter] || Reporter.get @persister = opts[:persister] || Persister.get(self) @name = Namer.new.name \ "#{opts[:name]}#{@type && @type.capitalize}Tracker" @persister.set_date(_set_date) end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
4 5 6 |
# File 'lib/reportier/tracker.rb', line 4 def defaults @defaults end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/reportier/tracker.rb', line 4 def name @name end |
#persister ⇒ Object (readonly)
Returns the value of attribute persister.
4 5 6 |
# File 'lib/reportier/tracker.rb', line 4 def persister @persister end |
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
4 5 6 |
# File 'lib/reportier/tracker.rb', line 4 def reporter @reporter end |
#started_at ⇒ Object
Returns the value of attribute started_at.
3 4 5 |
# File 'lib/reportier/tracker.rb', line 3 def started_at @started_at end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/reportier/tracker.rb', line 4 def type @type end |
Class Method Details
.[](type) ⇒ Object
7 8 9 10 |
# File 'lib/reportier/tracker.rb', line 7 def self.[](type) @current ||= Hash.new @current[type] ||= new(type: type) end |
Instance Method Details
#active? ⇒ Boolean
39 40 41 |
# File 'lib/reportier/tracker.rb', line 39 def active? DateTime.now < expires_at end |
#add(item) ⇒ Object
22 23 24 25 26 |
# File 'lib/reportier/tracker.rb', line 22 def add(item) (report && clear) unless active? return if Defaults.global.types[@type] == 0 @persister.save(Namer.new.name_item(item)) end |
#report ⇒ Object
28 29 30 31 32 33 |
# File 'lib/reportier/tracker.rb', line 28 def report @reporter.call(self) do "#{@type} report started at #{@started_at}\n" + @persister.report end end |
#to_json ⇒ Object
35 36 37 |
# File 'lib/reportier/tracker.rb', line 35 def to_json @persister.to_json end |