Class: Person
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Person
- Includes:
- Gravtastic
- Defined in:
- lib/punchcard/person.rb
Instance Method Summary collapse
- #payload ⇒ Object
-
#pending? ⇒ Boolean
Returns the currently pending punch when present, nil otherwise.
-
#punch! ⇒ Object
Punches in when no punches pending, punches out when a pending punch exists! When punching in, checks whether a recently finished punch exists and reopens if so instead of creating a new punch.
- #to_json(*args) ⇒ Object
Instance Method Details
#payload ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/punchcard/person.rb', line 29 def payload { :_id => id, :name => name, :email => email, :gravatar_url => gravatar_url(:size => 80), :pending => !!pending?, :checked_in_at => pending? ? pending?.checked_in_at.getutc.iso8601 : nil } end |
#pending? ⇒ Boolean
Returns the currently pending punch when present, nil otherwise
10 11 12 |
# File 'lib/punchcard/person.rb', line 10 def pending? punches.pending.count > 0 ? punches.pending.first : nil end |
#punch! ⇒ Object
Punches in when no punches pending, punches out when a pending punch exists! When punching in, checks whether a recently finished punch exists and reopens if so instead of creating a new punch
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/punchcard/person.rb', line 17 def punch! if punch = pending? punch.punch_out! else if recently_finished = punches.finished.first and recently_finished.checked_out_at.utc > 30.minutes.ago.utc recently_finished.reopen! else punches.create! end end end |
#to_json(*args) ⇒ Object
40 41 42 |
# File 'lib/punchcard/person.rb', line 40 def to_json(*args) payload.to_json end |