Class: LaunchdTools::EnvironmentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/launchd_tools/environment_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_doc) ⇒ EnvironmentParser

Returns a new instance of EnvironmentParser.



6
7
8
# File 'lib/launchd_tools/environment_parser.rb', line 6

def initialize(xml_doc)
  @xml_doc = xml_doc
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



5
6
7
# File 'lib/launchd_tools/environment_parser.rb', line 5

def element
  @element
end

#xml_docObject (readonly)

Returns the value of attribute xml_doc.



5
6
7
# File 'lib/launchd_tools/environment_parser.rb', line 5

def xml_doc
  @xml_doc
end

Instance Method Details

#extract_envObject



14
15
16
17
18
19
20
# File 'lib/launchd_tools/environment_parser.rb', line 14

def extract_env
  env = {}
  REXML::XPath.match(element, 'key').each do |environment_key|
    env[environment_key.text] = environment_key.next_sibling.next_sibling.text
  end
  env
end

#parseObject



22
23
24
25
26
27
28
# File 'lib/launchd_tools/environment_parser.rb', line 22

def parse
  if element
    extract_env
  else
    {}
  end
end