Class: Hocon::Impl::ConfigNodePath
- Inherits:
-
Object
- Object
- Hocon::Impl::ConfigNodePath
- Includes:
- AbstractConfigNode
- Defined in:
- lib/hocon/impl/config_node_path.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
- #first ⇒ Object
-
#initialize(path, tokens) ⇒ ConfigNodePath
constructor
A new instance of ConfigNodePath.
- #sub_path(to_remove) ⇒ Object
- #value ⇒ Object
Methods included from AbstractConfigNode
Methods included from Parser::ConfigNode
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
#tokens ⇒ Object (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
#first ⇒ Object
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
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 |
#value ⇒ Object
18 19 20 |
# File 'lib/hocon/impl/config_node_path.rb', line 18 def value @path end |