File: substitution_expression.rb

package info (click to toggle)
ruby-hocon 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 768 kB
  • sloc: ruby: 7,903; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 675 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
require_relative '../../hocon/impl'


class Hocon::Impl::SubstitutionExpression

  def initialize(path, optional)
    @path = path
    @optional = optional
  end
  attr_reader :path, :optional

  def change_path(new_path)
    if new_path == @path
      self
    else
      Hocon::Impl::SubstitutionExpression.new(new_path, @optional)
    end
  end

  def to_s
    "${#{@optional ? "?" : ""}#{@path.render}}"
  end

  def ==(other)
    if other.is_a? Hocon::Impl::SubstitutionExpression
      other.path == @path && other.optional == @optional
    else
      false
    end
  end

  def hash
    h = 41 * (41 + @path.hash)
    h = 41 * (h + (optional ? 1 : 0))

    h
  end
end