Class: Fig::TokenizedString::PlainSegment
- Inherits:
-
Object
- Object
- Fig::TokenizedString::PlainSegment
- Defined in:
- lib/fig/tokenized_string/plain_segment.rb
Instance Attribute Summary collapse
-
#raw_value ⇒ Object
readonly
Returns the value of attribute raw_value.
Instance Method Summary collapse
-
#initialize(raw_value) ⇒ PlainSegment
constructor
A new instance of PlainSegment.
-
#to_double_quotable_string(metacharacters) ⇒ Object
Should not be invoked if original string was not single quoted.
- #to_escaped_string ⇒ Object
- #to_expanded_string(&block) ⇒ Object
-
#to_single_quoted_string ⇒ Object
Should not be invoked if original string was single quoted.
- #type ⇒ Object
Constructor Details
#initialize(raw_value) ⇒ PlainSegment
Returns a new instance of PlainSegment.
9 10 11 12 13 |
# File 'lib/fig/tokenized_string/plain_segment.rb', line 9 def initialize(raw_value) @raw_value = raw_value return end |
Instance Attribute Details
#raw_value ⇒ Object (readonly)
Returns the value of attribute raw_value.
7 8 9 |
# File 'lib/fig/tokenized_string/plain_segment.rb', line 7 def raw_value @raw_value end |
Instance Method Details
#to_double_quotable_string(metacharacters) ⇒ Object
Should not be invoked if original string was not single quoted.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fig/tokenized_string/plain_segment.rb', line 37 def to_double_quotable_string() quoted_value = @raw_value.gsub %r< ( ["#{}] ) >xm, '\\\\\1' quoted_value.gsub!( %r< ( (?: ^ | [^\\] ) # New line or non-backslash (\\{2})* # Even number of backslashes ) # All single quotes must have been escaped. The important bit is to # not lose escaped backslashes. \\' >xm, %q<\1'> ) return quoted_value end |
#to_escaped_string ⇒ Object
23 24 25 |
# File 'lib/fig/tokenized_string/plain_segment.rb', line 23 def to_escaped_string() return @raw_value end |
#to_expanded_string(&block) ⇒ Object
19 20 21 |
# File 'lib/fig/tokenized_string/plain_segment.rb', line 19 def (&block) return @raw_value.gsub(%r< \\ (.) >xm, '\1') end |
#to_single_quoted_string ⇒ Object
Should not be invoked if original string was single quoted.
28 29 30 31 32 33 34 |
# File 'lib/fig/tokenized_string/plain_segment.rb', line 28 def to_single_quoted_string() # Raw value will have come from a non-single quoted string, so we unescape # everything (including backslashes) and then escape backslashes and single # quotes (which cannot be escaped outside of single quotes). return \ @raw_value.gsub(%r< \\ (.) >xm, '\1').gsub(%r< ([\\']) >xm, '\\\\\1') end |
#type ⇒ Object
15 16 17 |
# File 'lib/fig/tokenized_string/plain_segment.rb', line 15 def type return nil end |