Method: Mfd::Cli#prop_value_from_file

Defined in:
lib/mfd/cli.rb

#prop_value_from_file(filename, key) ⇒ Object



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/mfd/cli.rb', line 292

def prop_value_from_file(filename, key)
  filename = File.expand_path filename.sub(/^@/) { '' }
  IO.popen("mdls '#{filename}'", 'r') do |io|
    while line = io.gets
      next unless line =~ /#{key}\s*=\s*(.+)/
      value_str = Regexp.last_match(1)
      case value_str
      when /^"([^"]*)"$/
        return Regexp.last_match(1)
      when /^(\d+)$/
        return Regexp.last_match(1)
      when /^(.*) \+0000$/
        ymd = Regexp.last_match(1).split(/\D+/)
        return Time.gm(*ymd) - Time.gm(2001)
      else
        next
      end
    end
    return nil
  end
end