Passed
Push — master ( 23b088...27bc68 )
by Ahmad
06:31
created

RecordingsHelper.recording_length()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 9
rs 9.95
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 a nice length string.
21
  def recording_length(playbacks)
22
    # Looping through playbacks array and returning first non-zero length value
23
    playbacks.each do |playback|
24
      length = playback[:length]
25
      return recording_length_string(length) unless length.zero?
26
    end
27
    # Return '< 1 min' if length values are zero
28
    "< 1 min"
29
  end
30
31
  # Prevents single images from erroring when not passed as an array.
32
  def safe_recording_images(images)
33
    Array.wrap(images)
34
  end
35
36
  def room_uid_from_bbb(bbb_id)
37
    Room.find_by(bbb_id: bbb_id)[:uid]
38
  end
39
40
  # returns whether recording thumbnails are enabled on the server
41
  def recording_thumbnails?
42
    Rails.configuration.recording_thumbnails
43
  end
44
45
  private
46
47
  # Returns length of the recording as a string
48
  def recording_length_string(len)
49
    if len > 60
50
      "#{(len / 60).to_i} h #{len % 60} min"
51
    else
52
      "#{len} min"
53
    end
54
  end
55
end
56