Passed
Push — master ( 6bc43d...2da2ee )
by Ahmad
07:04
created

RecordingsHelper.recording_length_string()   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
# frozen_string_literal: true
2
3
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
#
5
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
6
#
7
# This program is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU Lesser General Public License as published by the Free Software
9
# Foundation; either version 3.0 of the License, or (at your option) any later
10
# version.
11
#
12
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
#
16
# You should have received a copy of the GNU Lesser General Public License along
17
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
19
module RecordingsHelper
20
  # Helper for converting BigBlueButton dates into the desired format.
21
  def recording_date(date)
22
    I18n.l date, format: "%B %d, %Y"
23
  end
24
25
  # Helper for converting BigBlueButton dates into a nice length string.
26
  def recording_length(playbacks)
27
    # Looping through playbacks array and returning first non-zero length value
28
    playbacks.each do |playback|
29
      length = playback[:length]
30
      return recording_length_string(length) unless length.zero?
31
    end
32
    # Return '< 1 min' if length values are zero
33
    "< 1 min"
34
  end
35
36
  # Prevents single images from erroring when not passed as an array.
37
  def safe_recording_images(images)
38
    Array.wrap(images)
39
  end
40
41
  def room_uid_from_bbb(bbb_id)
42
    Room.find_by(bbb_id: bbb_id)[:uid]
43
  end
44
45
  # returns whether recording thumbnails are enabled on the server
46
  def recording_thumbnails?
47
    Rails.configuration.recording_thumbnails
48
  end
49
50
  private
51
52
  # Returns length of the recording as a string
53
  def recording_length_string(len)
54
    if len > 60
55
      "#{(len / 60).to_i} h #{len % 60} min"
56
    else
57
      "#{len} min"
58
    end
59
  end
60
end
61