Sha256: e23447ca05e5d2061189c1a7134211132625046a17df3430ce6c23e41c917c99
Contents?: true
Size: 1.53 KB
Versions: 1
Compression:
Stored size: 1.53 KB
Contents
require_relative 'options' module CookbookReader class Parser def initialize(argv) @options = Options.new(argv) @top_list = [] end def parse @metadata_list = Array.new Dir.glob("#{@options.path_to_search}/**/metadata.rb") do |filename| @metadata_list.push read_file filename end end def display_data @top_list.each do |element| puts "Cookbook: #{element['name']}\n" puts " Dependancies:" element['depends'].each do |name, version| puts " #{name}, #{version}\n" end puts "\n" end end private def read_file(filename) @hash = {} @depends_list = {} File.open(filename) do |fp| fp.each do |line| key, value = line.chomp.split(" ") key.strip! value.strip! key = key.chomp('"').reverse.chomp('"').reverse value = value.chomp('"').reverse.chomp('"').reverse if key =~ /depends/ @hash[key] = add_dependencies(line) else @hash[key] = value end end end @top_list.push @hash end def add_dependencies(line) line.slice! "depends " k, v = line.chomp.split(",") v = "none" if v.nil? k.strip! v.strip! v = v.chomp('"').reverse.chomp('"').reverse v = v.chomp('"').reverse.chomp('"').reverse k = k.chomp('"').reverse.chomp('"').reverse k.strip! v.strip! @depends_list[k] = v @depends_list end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cookbook-reader-0.1.1 | lib/cookbook-reader/parser.rb |