Segment.index()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
1
# frozen_string_literal: true
2
3
module AMA
4
  module Entity
5
    class Mapper
6
      class Path
7
        # Well, that's quite self-explanatory. Path consists of segments, and
8
        # here's one.
9
        class Segment
10
          attr_reader :name
11
          attr_reader :prefix
12
          attr_reader :suffix
13
14
          def initialize(name, prefix = nil, suffix = nil)
15
            @name = name
16
            @prefix = prefix
17
            @suffix = suffix
18
          end
19
20
          def to_s
21
            "#{@prefix}#{@name}#{@suffix}"
22
          end
23
24
          def hash
25
            @name.hash ^ @prefix.hash ^ @suffix.hash
26
          end
27
28
          def eql?(other)
29
            return false unless other.is_a?(self.class)
30
            @name == other.name && @prefix == other.prefix &&
31
              @suffix == other.suffix
32
          end
33
34
          def ==(other)
35
            eql?(other)
36
          end
37
38
          class << self
39
            def attribute(name)
40
              new(name, '.')
41
            end
42
43
            def index(name)
44
              new(name, '[', ']')
45
            end
46
          end
47
        end
48
      end
49
    end
50
  end
51
end
52