Class: Bloomy::Scorecard
- Inherits:
-
Object
- Object
- Bloomy::Scorecard
- Includes:
- Utilities::UserIdUtility
- Defined in:
- lib/bloomy/operations/scorecard.rb
Overview
This class is already initialized via the client and usable as ‘client.scorecard.method`
Class to handle all the operations related to scorecards
Instance Method Summary collapse
-
#current_week ⇒ Hash
Retrieves the current week details.
-
#initialize(conn) ⇒ Scorecard
constructor
Initializes a new Scorecard instance.
-
#list(user_id: nil, meeting_id: nil, show_empty: false, week_offset: nil) ⇒ Array<Hash>
Retrieves the scorecards for a user or a meeting.
-
#score(measurable_id:, score:, week_offset: 0) ⇒ Boolean
Updates the score for a measurable item for a specific week.
Methods included from Utilities::UserIdUtility
Constructor Details
#initialize(conn) ⇒ Scorecard
Initializes a new Scorecard instance
16 17 18 |
# File 'lib/bloomy/operations/scorecard.rb', line 16 def initialize(conn) @conn = conn end |
Instance Method Details
#current_week ⇒ Hash
Retrieves the current week details
26 27 28 29 30 31 32 33 34 |
# File 'lib/bloomy/operations/scorecard.rb', line 26 def current_week response = @conn.get("weeks/current").body { id: response["Id"], week_number: response["ForWeekNumber"], week_start: response["LocalDate"]["Date"], week_end: response["ForWeek"] } end |
#list(user_id: nil, meeting_id: nil, show_empty: false, week_offset: nil) ⇒ Array<Hash>
The ‘week_offset` parameter is useful when fetching scores for previous or future weeks. For example, to fetch scores for the previous week, you can set `week_offset` to -1. To fetch scores for a future week, you can set `week_offset` to a positive value.
Retrieves the scorecards for a user or a meeting.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bloomy/operations/scorecard.rb', line 57 def list(user_id: nil, meeting_id: nil, show_empty: false, week_offset: nil) raise ArgumentError, "Please provide either `user_id` or `meeting_id`, not both." if user_id && meeting_id if meeting_id response = @conn.get("scorecard/meeting/#{meeting_id}").body else user_id ||= self.user_id response = @conn.get("scorecard/user/#{user_id}").body end scorecards = response["Scores"].map do |scorecard| { id: scorecard["Id"], measurable_id: scorecard["MeasurableId"], accountable_user_id: scorecard["AccountableUserId"], title: scorecard["MeasurableName"], target: scorecard["Target"], value: scorecard["Measured"], week: scorecard["Week"], week_id: scorecard["ForWeek"], updated_at: scorecard["DateEntered"] } end if week_offset week_data = current_week week_id = week_data[:week_number] + week_offset scorecards.select! { |scorecard| scorecard[:week_id] == week_id } end scorecards.select! { |scorecard| scorecard[:value] || show_empty } unless show_empty scorecards end |
#score(measurable_id:, score:, week_offset: 0) ⇒ Boolean
Updates the score for a measurable item for a specific week.
100 101 102 103 104 105 106 |
# File 'lib/bloomy/operations/scorecard.rb', line 100 def score(measurable_id:, score:, week_offset: 0) week_data = current_week week_id = week_data[:week_number] + week_offset response = @conn.put("measurables/#{measurable_id}/week/#{week_id}", {value: score}.to_json) response.success? end |