Class: Suc::Reports::Personal

Inherits:
Object
  • Object
show all
Defined in:
lib/reports/personal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year, week, scope = 'person') ⇒ Personal

Returns a new instance of Personal.



9
10
11
12
13
14
15
16
# File 'lib/reports/personal.rb', line 9

def initialize(year, week, scope='person')
  @week = week
  @year = year
  resource = '/api/years/%s/weeks/%s/messages' % [year, week]
  response = RestClient.get(Suc.resource_url(resource).to_s, { params: { scope: scope }, authorization: Suc.token_auth })
  @messages = Message.from_json(response)
  @email = Email.new(self)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/reports/personal.rb', line 7

def body
  @body
end

#emailObject (readonly)

Returns the value of attribute email.



7
8
9
# File 'lib/reports/personal.rb', line 7

def email
  @email
end

#weekObject (readonly)

Returns the value of attribute week.



7
8
9
# File 'lib/reports/personal.rb', line 7

def week
  @week
end

#yearObject (readonly)

Returns the value of attribute year.



7
8
9
# File 'lib/reports/personal.rb', line 7

def year
  @year
end

Instance Method Details

#exportObject



29
30
31
# File 'lib/reports/personal.rb', line 29

def export
  email.export
end

#grouped_by_colorObject



18
19
20
# File 'lib/reports/personal.rb', line 18

def grouped_by_color
  @messages.group_by{|x| x.color}.sort_by{|x| x.first.length}
end


22
23
24
25
26
27
# File 'lib/reports/personal.rb', line 22

def print
  file = File.read File.join(File.dirname(__FILE__), '../templates/personal_report.erb')
  template = ERB.new(file, 0, '-<>')
  @body = template.result(binding)
  puts @body
end