~singpolyma/sgx-jmp

ref: a9ebca9a66da1fa0e10bee066a6ba71fe31177a3 sgx-jmp/lib/usage_report.rb -rw-r--r-- 943 bytes
a9ebca9aStephen Paul Weber Usage command 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require_relative "./form_table"

class UsageReport
	def initialize(report_for, messages, minutes)
		@report_for = report_for
		@messages = messages
		@minutes = minutes
	end

	def ==(other)
		report_for == other.report_for &&
			messages == other.messages &&
			minutes == other.minutes
	end

	def form
		form = Blather::Stanza::X.new(:result)
		form.title =
			form.instructions =
				"Usage from #{report_for.first} to #{report_for.last}"
		form_table.add_to_form(form)
		form
	end

	def form_table
		total_messages = 0
		total_minutes = 0

		FormTable.new(
			@report_for.first.downto(@report_for.last).map do |day|
				total_messages += @messages[day]
				total_minutes += @minutes[day]
				[day, @messages[day], @minutes[day]]
			end + [["Total", total_messages, total_minutes]],
			day: "Day", messages: "Messages", minutes: "Minutes"
		)
	end

protected

	attr_reader :report_for, :messages, :minutes
end