class Goal::Calculator
Attributes
base[R]
calculator[R]
goal_list[R]
hours[R]
money_rate[R]
project_id[R]
start_day[R]
token[R]
username[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/goal.rb, line 7 def initialize(options = {}) @goal_list = options.fetch(:goal_list, [160, 200, 250, 300]) @username = options[:username] @token = options[:token] @project_id = options[:project_id] @hours = options[:hours] @money_rate = options[:money_rate] @start_day = options.fetch(:start_day, 1) @calculator = Goal::HourCalculator.new(start_day) end
Public Instance Methods
generate_data()
click to toggle source
# File lib/goal.rb, line 37 def generate_data data = {} data[:rows] = goals data[:summary] = summary data end
rate()
click to toggle source
It calculates the current hour rate
# File lib/goal.rb, line 33 def rate calculator.hour_rate(worked_time).round(2) end
total_money()
click to toggle source
# File lib/goal.rb, line 28 def total_money (worked_time * money_rate).round(2) end
worked_time()
click to toggle source
# File lib/goal.rb, line 18 def worked_time @time ||= if hours hours elsif username && token && project_id freshbooks.hours else 0 end.round(2) end
Private Instance Methods
freshbooks()
click to toggle source
# File lib/goal.rb, line 51 def freshbooks Goal::FreshbooksCalculator.new(username, token, project_id, start_day) end
goals()
click to toggle source
# File lib/goal.rb, line 55 def goals calculated_goals = [] goal_list.each do |goal| calculated_goals.push({ goal: goal, expected: calculator.estimated_for(goal).round(2), average: calculator.rate_to_goal(goal, worked_time).round(2) }) end calculated_goals end
summary()
click to toggle source
# File lib/goal.rb, line 69 def summary data = { total_time: worked_time, rate: rate, days_left: calculator.days_left } data[:money] = total_money if money_rate data end