Module: ImageMagick::Identify::Parser

Defined in:
lib/imagemagick/identify/parser.rb

Constant Summary collapse

INDENT_PER_LEVEL =
2

Class Method Summary collapse

Class Method Details

.parse(input, spaces = INDENT_PER_LEVEL) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/imagemagick/identify/parser.rb', line 9

def self.parse(input, spaces = INDENT_PER_LEVEL)
  matcher = /\n\s{#{spaces}}\b/ #new line with n spaces until the next word

  {}.tap{ |result|
    input.split(matcher).each do |string|
      if string.include?(":\n")
        key, value = string.split(":\n", 2).map(&:strip)
        result[key] = parse(value, spaces + INDENT_PER_LEVEL)
      else
        key, value = string.split(": ", 2).map(&:strip)
        result[key] = value
      end
    end
  }
end