class Paymo::Extras
Public Class Methods
new(user_id)
click to toggle source
# File lib/paymo/extras.rb, line 4 def initialize(user_id) @paymo_entries_instance = Paymo::Entries.new @cache_instance = Cache.new(Paymo::Projects.new, :price_per_hour) @end_time = Time.now @user_id = user_id end
Public Instance Methods
earnt_this_month?()
click to toggle source
# File lib/paymo/extras.rb, line 20 def earnt_this_month? run Time.new(Time.now.year, Time.now.month) end
earnt_this_week?()
click to toggle source
# File lib/paymo/extras.rb, line 15 def earnt_this_week? start = Date.today + 1 - Date.today.wday run start.to_time end
earnt_today?()
click to toggle source
# File lib/paymo/extras.rb, line 11 def earnt_today? run Date.today.to_time end
Private Instance Methods
build_per_hour_and_total()
click to toggle source
# File lib/paymo/extras.rb, line 51 def build_per_hour_and_total @project_ids_and_hours.each do |entry| entry[:per_hour] = @cache_instance.get(entry[:project_id]) entry[:total] = (entry[:per_hour] * entry[:hours]) end end
build_projects_and_hours()
click to toggle source
# File lib/paymo/extras.rb, line 42 def build_projects_and_hours @project_ids_and_hours = @entries.map do |entry| { project_id: entry.project_id, hours: span_of_hours_to_hours(entry) } end end
get_entries()
click to toggle source
# File lib/paymo/extras.rb, line 38 def get_entries @entries = @paymo_entries_instance.find_by_user(@user_id, start: @start_time, end: @end_time) end
run(time)
click to toggle source
# File lib/paymo/extras.rb, line 26 def run(time) @start_time = time get_entries if @entries build_projects_and_hours build_per_hour_and_total sum_total_overall_hours else 0.00 end end
span_of_hours_to_hours(entry)
click to toggle source
# File lib/paymo/extras.rb, line 62 def span_of_hours_to_hours(entry) ((entry.end.to_time - entry.start.to_time) / 60 / 60) end
sum_total_overall_hours()
click to toggle source
# File lib/paymo/extras.rb, line 58 def sum_total_overall_hours @project_ids_and_hours.inject(0) { |sum, hash| sum + hash[:total] } end