Module: Walky::Parser

Defined in:
lib/walky/parser.rb

Class Method Summary collapse

Class Method Details

.extract(hash, path) ⇒ Object



20
21
22
# File 'lib/walky/parser.rb', line 20

def self.extract(hash, path)
  Walky.move(hash, path)
end

.extract_with_sym(hash, path) ⇒ Object



24
25
26
# File 'lib/walky/parser.rb', line 24

def self.extract_with_sym(hash, path)
  symbolize_keys(extract(hash, path))
end

.parse(hash, path) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/walky/parser.rb', line 3

def self.parse(hash, path)
  paths = path.split(" ")
  return_hash = hash
  paths.each do |pathy|
    if pathy =~ /^:/
      return_hash = return_hash[pathy.gsub(":", "").to_sym]
    else
      return_hash = return_hash[pathy]
    end
  end

  return_hash.extend InstanceMethods
  return_hash.walky_path = path

  return_hash
end

.symbolize_keys(hash) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/walky/parser.rb', line 28

def self.symbolize_keys(hash)
  {}.tap do |h|
    hash.each do |key, value|
      h[key.to_sym] = value
    end
  end
end