Class: Hocon::Impl::Path
- Inherits:
-
Object
- Object
- Hocon::Impl::Path
- Defined in:
- lib/hocon/impl/path.rb
Instance Attribute Summary collapse
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#remainder ⇒ Object
readonly
Returns the value of attribute remainder.
Class Method Summary collapse
-
.has_funky_chars?(s) ⇒ Boolean
this doesn’t have a very precise meaning, just to reduce noise from quotes in the rendered path for average cases.
Instance Method Summary collapse
- #append_to_string_builder(sb) ⇒ Object
-
#initialize(first, remainder) ⇒ Path
constructor
A new instance of Path.
-
#render ⇒ Object
toString() is a debugging-oriented version while this is an error-message-oriented human-readable one.
Constructor Details
#initialize(first, remainder) ⇒ Path
Returns a new instance of Path.
31 32 33 34 |
# File 'lib/hocon/impl/path.rb', line 31 def initialize(first, remainder) @first = first @remainder = remainder end |
Instance Attribute Details
#first ⇒ Object (readonly)
Returns the value of attribute first.
35 36 37 |
# File 'lib/hocon/impl/path.rb', line 35 def first @first end |
#remainder ⇒ Object (readonly)
Returns the value of attribute remainder.
35 36 37 |
# File 'lib/hocon/impl/path.rb', line 35 def remainder @remainder end |
Class Method Details
.has_funky_chars?(s) ⇒ Boolean
this doesn’t have a very precise meaning, just to reduce noise from quotes in the rendered path for average cases
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hocon/impl/path.rb', line 7 def self.has_funky_chars?(s) length = s.length if length == 0 return false end # if the path starts with something that could be a number, # we need to quote it because the number could be invalid, # for example it could be a hyphen with no digit afterward # or the exponent "e" notation could be mangled. first = s[0] unless first =~ /[[:alpha:]]/ return true end s.chars.each do |c| unless (c =~ /[[:alnum:]]/) || (c == '-') || (c == '_') return true end end false end |
Instance Method Details
#append_to_string_builder(sb) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/hocon/impl/path.rb', line 47 def append_to_string_builder(sb) if self.class.has_funky_chars?(@first) || @first.empty? sb << ConfigImplUtil.render_json_string(@first) else sb << @first end unless @remainder.nil? sb << "." @remainder.append_to_string_builder(sb) end end |
#render ⇒ Object
toString() is a debugging-oriented version while this is an error-message-oriented human-readable one.
41 42 43 44 45 |
# File 'lib/hocon/impl/path.rb', line 41 def render sb = StringIO.new append_to_string_builder(sb) sb.string end |