Class: Measurable
- Inherits:
-
Object
- Object
- Measurable
- Defined in:
- lib/bloomy/operations/measurables.rb
Overview
Note:
This class is already initialized via the client and usable as ‘client.measurable.method`
Class to handle all the operations related to measurables
Instance Method Summary collapse
-
#current_week ⇒ Hash
Retrieves the current week details.
-
#initialize(conn, user_id) ⇒ Measurable
constructor
Initializes a new Measurable instance.
-
#scorecard(current_week_only: true, show_empty: true) ⇒ Array<Hash>
Retrieves the scorecard for the user.
-
#update(scorecard_id, measured) ⇒ Boolean
Updates a scorecard with a new measured value.
Constructor Details
#initialize(conn, user_id) ⇒ Measurable
Initializes a new Measurable instance
13 14 15 16 |
# File 'lib/bloomy/operations/measurables.rb', line 13 def initialize(conn, user_id) @conn = conn @user_id = user_id end |
Instance Method Details
#current_week ⇒ Hash
Retrieves the current week details
24 25 26 27 28 29 30 31 32 |
# File 'lib/bloomy/operations/measurables.rb', line 24 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 |
#scorecard(current_week_only: true, show_empty: true) ⇒ Array<Hash>
Retrieves the scorecard for the user
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bloomy/operations/measurables.rb', line 42 def scorecard(current_week_only: true, show_empty: true) response = @conn.get("scorecard/user/mine").body scorecards = response["Scores"].map do |scorecard| { id: scorecard["Id"], title: scorecard["MeasurableName"], target: scorecard["Target"], value: scorecard["Measured"], updated_at: scorecard["DateEntered"], week_number: scorecard["ForWeek"] } end if current_week_only week_id = current_week[:week_number] scorecards.select do |scorecard| scorecard[:week_number] == week_id && (show_empty || scorecard[:value].nil?) end else scorecards.select { |scorecard| show_empty || scorecard[:value].nil? } end end |
#update(scorecard_id, measured) ⇒ Boolean
Updates a scorecard with a new measured value
73 74 75 76 |
# File 'lib/bloomy/operations/measurables.rb', line 73 def update(scorecard_id, measured) response = @conn.put("scores/#{scorecard_id}", {value: measured}.to_json).status response == 200 end |