Class: Hocon::Impl::ConfigNodePath

Inherits:
Object
  • Object
show all
Includes:
AbstractConfigNode
Defined in:
lib/hocon/impl/config_node_path.rb

Constant Summary collapse

Tokens =
Hocon::Impl::Tokens

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AbstractConfigNode

#==, #hash, #render

Methods included from Parser::ConfigNode

#render

Constructor Details

#initialize(path, tokens) ⇒ ConfigNodePath

Returns a new instance of ConfigNodePath.



11
12
13
14
# File 'lib/hocon/impl/config_node_path.rb', line 11

def initialize(path, tokens)
  @path = path
  @tokens = tokens
end

Instance Attribute Details

#tokensObject (readonly)

Returns the value of attribute tokens.



16
17
18
# File 'lib/hocon/impl/config_node_path.rb', line 16

def tokens
  @tokens
end

Instance Method Details

#firstObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/hocon/impl/config_node_path.rb', line 38

def first
  tokens_copy = tokens.clone
  (0..tokens_copy.size - 1).each do |i|
    if Tokens.unquoted_text?(tokens_copy[i]) &&
        tokens_copy[i].token_text == "."
      return self.class.new(@path.sub_path(0, 1), tokens_copy[0, i])
    end
  end
  self
end

#sub_path(to_remove) ⇒ Object

Raises:

  • (ConfigBugOrBrokenError)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hocon/impl/config_node_path.rb', line 22

def sub_path(to_remove)
  period_count = 0
  tokens_copy = tokens.clone
  (0..tokens_copy.size - 1).each do |i|
    if Tokens.unquoted_text?(tokens_copy[i]) &&
        tokens_copy[i].token_text == "."
      period_count += 1
    end

    if period_count == to_remove
      return self.class.new(@path.sub_path_to_end(to_remove), tokens_copy[i + 1..tokens_copy.size])
    end
  end
  raise ConfigBugOrBrokenError, "Tried to remove too many elements from a Path node"
end

#valueObject



18
19
20
# File 'lib/hocon/impl/config_node_path.rb', line 18

def value
  @path
end