Class: VagrantVbguest::Helpers::OsRelease::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vbguest/helpers/os_release.rb

Overview

This class enables parsing of a string for key value pairs to be returned and stored in the Environment. It allows for variable substitutions and exporting of variables.

Constant Summary collapse

LINE =
/
  \A
  (?:export\s+)?    # optional export
  ([\w\.]+)         # key
  (?:\s*=\s*|:\s+?) # separator
  (                 # optional value begin
    '(?:\'|[^'])*'  #   single quoted value
    |               #   or
    "(?:\"|[^"])*"  #   double quoted value
    |               #   or
    [^#\n]+         #   unquoted value
  )?                # value end
  (?:\s*\#.*)?      # optional comment
  \z
/x

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Parser

Returns a new instance of Parser.



120
121
122
123
# File 'lib/vagrant-vbguest/helpers/os_release.rb', line 120

def initialize(string)
  @string = string
  @hash = {}
end

Class Attribute Details

.substitutionsObject (readonly)

Returns the value of attribute substitutions.



113
114
115
# File 'lib/vagrant-vbguest/helpers/os_release.rb', line 113

def substitutions
  @substitutions
end

Class Method Details

.call(string) ⇒ Object



115
116
117
# File 'lib/vagrant-vbguest/helpers/os_release.rb', line 115

def call(string)
  new(string).call
end

Instance Method Details

#callObject



125
126
127
128
129
130
# File 'lib/vagrant-vbguest/helpers/os_release.rb', line 125

def call
  @string.split(/[\n\r]+/).each do |line|
    parse_line(line)
  end
  @hash
end