summaryrefslogtreecommitdiff
path: root/lib/gitlab/diff/formatters/image_formatter.rb
blob: 5bc9f0c337f50509765ccb63e040c8e9f199953f (plain)
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
# frozen_string_literal: true

module Gitlab
  module Diff
    module Formatters
      class ImageFormatter < BaseFormatter
        attr_reader :width
        attr_reader :height
        attr_reader :x
        attr_reader :y

        def initialize(attrs)
          @x = attrs[:x]
          @y = attrs[:y]
          @width = attrs[:width]
          @height = attrs[:height]

          super(attrs)
        end

        def key
          @key ||= super.push(x, y)
        end

        def complete?
          x && y && width && height
        end

        def to_h
          super.merge(width: width, height: height, x: x, y: y)
        end

        def position_type
          "image"
        end

        def ==(other)
          other.is_a?(self.class) &&
            x == other.x &&
            y == other.y
        end
      end
    end
  end
end