Class: Fig::TokenizedString

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/tokenized_string.rb,
lib/fig/tokenized_string/token.rb,
lib/fig/tokenized_string/plain_segment.rb

Defined Under Namespace

Classes: PlainSegment, Token

Instance Method Summary collapse

Constructor Details

#initialize(segments, single_quoted, metacharacters) ⇒ TokenizedString

Returns a new instance of TokenizedString.


6
7
8
9
10
11
12
# File 'lib/fig/tokenized_string.rb', line 6

def initialize(segments, single_quoted, metacharacters)
  @segments       = segments
  @single_quoted  = single_quoted
  @metacharacters = metacharacters

  return
end

Instance Method Details

#can_be_single_quoted?Boolean

Returns:

  • (Boolean)

18
19
20
21
# File 'lib/fig/tokenized_string.rb', line 18

def can_be_single_quoted?()
  return true if single_quoted?
  return @segments.all? {|segment| segment.type.nil?}
end

#single_quoted?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/fig/tokenized_string.rb', line 14

def single_quoted?()
  return @single_quoted
end

#to_double_quotable_stringObject


41
42
43
44
45
46
47
48
49
# File 'lib/fig/tokenized_string.rb', line 41

def to_double_quotable_string()
  return to_escaped_string if ! single_quoted?

  return (
    @segments.collect {
      |segment| segment.to_double_quotable_string @metacharacters
    }
  ).join ''
end

#to_escaped_stringObject


29
30
31
# File 'lib/fig/tokenized_string.rb', line 29

def to_escaped_string()
  return ( @segments.collect {|segment| segment.to_escaped_string} ).join ''
end

#to_expanded_string(&block) ⇒ Object


23
24
25
26
27
# File 'lib/fig/tokenized_string.rb', line 23

def to_expanded_string(&block)
  return (
    @segments.collect { |segment| segment.to_expanded_string(&block) }
  ).join ''
end

#to_single_quoted_stringObject


33
34
35
36
37
38
39
# File 'lib/fig/tokenized_string.rb', line 33

def to_single_quoted_string()
  return to_escaped_string if single_quoted?

  return (
    @segments.collect {|segment| segment.to_single_quoted_string}
  ).join ''
end