| Total Complexity | 8 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # frozen_string_literal: true |
||
| 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 |
||
| 52 |