Passed
Push — master ( b5e814...87219b )
by Sascha
02:12
created

PublicanCreatorsPrepare.targetdir()   B

Complexity

Conditions 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 4
c 3
b 1
f 0
dl 0
loc 22
rs 8.9197
1
# Copyright (C) 2013-2017 Sascha Manns <[email protected]>
2
#
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16
# Dependencies
17
18
# The module Prepare contains some methods for preparing the directories. They
19
# will be used in the make directory function
20
module PublicanCreatorsPrepare
21
  # This method sets the needed targetdir depending on the environment
22
  # @param [String] environment Work or Private
23
  # @param [String] type represents the Document-Type like Article or Book.
24
  # @param [String] reports_dir_business contains the directory to your reports
25
  # @param [String] articles_dir_bus represents the directory for your articles
26
  # @param [String] report contains a true or false. There you can set if the
27
  #                 new Publication is a Report or not.
28
  # @param [String] books_dir_business contains the directory for your business
29
  #                 books
30
  # @param [String] homework contains true or false. If your present Publication
31
  #                 is a homework you can set it there.
32
  # @param [String] articles_dir_private contains the path to your private
33
  #                 articles_dir
34
  # @param [String] homework_dir_private contains the path to your homework dir.
35
  # @param [String] books_dir_private contains the path to your private
36
  #                 books_dir
37
  # @return [String] targetdir
38
  def self.targetdir(environment, type, report, reports_dir_business,
39
                     articles_dir_bus, books_dir_business, homework,
40
                     articles_dir_private, homework_dir_private, books_dir_private)
41
    home = Dir.home
42
    # TODO: Try to fix this in future
43
    # rubocop:disable Style/IfInsideElse
44
    if environment == 'Work'
45
      if type == 'Article'
46
        targetdir_work(report, reports_dir_business, articles_dir_bus)
47
      else
48
        books_dir = "#{home}/#{books_dir_business}"
49
        return books_dir
50
      end
51
    else
52
      if type == 'Article'
53
        targetdir_private(homework, articles_dir_private, homework_dir_private)
54
      else
55
        books_dir = "#{home}/#{books_dir_private}"
56
        return books_dir
57
      end
58
    end
59
  end
60
61
  # Prepares the articles_dir for work environment
62
  # @param [String] report contains a true or false. There you can set if the
63
  #                 new Publication is a Report or not.
64
  # @param [String] reports_dir_business contains the directory to your reports
65
  # @param [String] articles_dir_bus represents the directory for your articles
66 View Code Duplication
  def self.targetdir_work(report, reports_dir_business, articles_dir_bus)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
67
    home = Dir.home
68
    articles_dir = if report == 'TRUE'
69
                     "#{home}/#{reports_dir_business}"
70
                   else
71
                     "#{home}/#{articles_dir_bus}"
72
                   end
73
    return articles_dir
74
  end
75
76
  # Prepares the articles_dir for home environment
77
  # @param [String] homework contains true or false. If your present Publication
78
  #                 is a homework you can set it there.
79
  # @param [String] articles_dir_private contains the path to your private
80
  #                 articles_dir
81
  # @param [String] homework_dir_private contains the path to your homework dir.
82 View Code Duplication
  def self.targetdir_private(homework, articles_dir_private, homework_dir_private)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
83
    home = Dir.home
84
    articles_dir = if homework == 'FALSE'
85
                     "#{home}/#{articles_dir_private}"
86
                   else
87
                     "#{home}/#{homework_dir_private}"
88
                   end
89
    return articles_dir
90
  end
91
end
92