Completed
Push — feature/add-more-attributes-to... ( e662dc...b821bf )
by
unknown
02:12
created

SessionsJsonBuilder.to_json()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 4
rs 10
1
class SessionsJsonBuilder
2
3
  def to_hash(session) 
4
    s = session
5
    { id: s.id,
6
      participant_id: s.participant.id,
7
      presenter_name: s.participant.name,
8
      presenter_twitter_handle: s.participant.twitter_handle,
9
      presenter_github_username: s.participant.github_profile_username,
10
      presenter_github_og_image: s.participant.github_og_image,
11
      session_title: s.title,
12
      summary: s.summary,
13
      description: s.description,
14
      room_name: s.room_name,
15
      panel: s.panel,
16
      projector: s.projector,
17
      starts_at: s.starts_at,
18
      level_name: s.level_name,
19
      categories: s.categories.map(&:name),
20
      other_presenter_names: s.other_presenter_names,
21
      other_presenter_ids: s.other_presenters.map(&:id),
22
      attendance_count: s.attendances.count,
23
      created_at: s.created_at.utc,
24
      updated_at: s.updated_at.utc
25
    }
26
  end
27
28
  def to_json(sessions)
29
    require 'json'
30
    JSON.pretty_generate(sessions.map(&:to_h))
31
  end
32
  
33
end
34