File: section.rb

package info (click to toggle)
ruby-riddle 2.3.1-2~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,752 kB
  • sloc: sql: 25,022; php: 5,992; ruby: 4,757; sh: 59; makefile: 5
file content (61 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

module Riddle
  class Configuration
    class Section
      def self.settings
        []
      end

      def valid?
        true
      end

      private

      def settings_body
        settings.select { |setting|
          !send(setting).nil?
        }.collect { |setting|
          if send(setting) == ""
            conf = "  #{setting} = "
          else
            conf = setting_to_array(setting).collect { |set|
              "  #{setting} = #{rendered_setting set}"
            }
          end
          conf.length == 0 ? nil : conf
        }.flatten.compact
      end

      def setting_to_array(setting)
        value = send(setting)
        case value
        when Array      then value
        when TrueClass  then [1]
        when FalseClass then [0]
        else
          [value]
        end
      end

      def rendered_setting(setting)
        return setting unless setting.is_a?(String)

        index  = 8100
        output = String.new(setting)

        while index < output.length
          output.insert(index, "\\\n")
          index += 8100
        end

        output
      end

      def settings
        self.class.settings
      end
    end
  end
end