Passed
Push — master ( e9b4be...fdfd44 )
by Paul
01:35
created

Header.header_sections()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 7
ccs 2
cts 2
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1 1
module Resume
2 1
  module PDF
3 1
    module Entry
4 1
      module Header
5 1
        module_function
6
7 1
        def generate(pdf, entry)
8
          # Different rendering behaviour needed depending on whether
9
          # the header is being drawn from left to right on the page
10
          # or specifically placed at a location on the x-axis
11 12
          entry_header_sections = header_sections(entry)
12 12
          if (x_position = entry[:at_x_position])
13 2
            formatted_text_box_header(entry_header_sections, pdf, x_position)
14
          else
15 10
            formatted_text_header(entry_header_sections, pdf)
16
          end
17
        end
18
19 1
        def formatted_text_box_header(header_sections, pdf, x_position)
20 2
          header_sections.each do |sections|
21 6
            pdf.formatted_text_box(
22 8
              sections.map { |section| properties_for(section) },
23
              at: [x_position, pdf.cursor]
24
            )
25 6
            pdf.move_down(sections.first[:bottom_padding])
26
          end
27
        end
28 1
        private_class_method :formatted_text_box_header
29
30 1
        def formatted_text_header(header_sections, pdf)
31 10
          header_sections.each do |sections|
32 30
            pdf.formatted_text(
33 40
              sections.map { |section| properties_for(section) }
34
            )
35
          end
36
        end
37 1
        private_class_method :formatted_text_header
38
39 1
        def header_sections(entry)
40
          [
41 12
            [entry[:position]],
42
            [entry[:organisation]],
43
            [entry[:period], entry[:location]]
44
          ]
45
        end
46 1
        private_class_method :header_sections
47
48 1
        def properties_for(section)
49
          {
50
            text: section[:text],
51
            styles: section[:styles],
52
            size: section[:size],
53
            color: section[:colour],
54
            link: section[:link]
55 48
          }
56
        end
57 1
        private_class_method :properties_for
58
      end
59
    end
60
  end
61
end
62