Sha256: c4c48d36d9243e070afd2ebe10d953d23f9526b98e342bf78ed6f1717aecbd04
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
class DataProcessor module Import def import(path="", data_obj=nil) path = path.sub(/^\/+/, "") path = path.sub(/\/+$/, "") data_hash = data_obj || @data full_path = File.join(@initial_path, path) Dir.foreach(full_path) do |filename| next if filename[0] == "." combined_path = File.join(full_path, filename) # directory if File.directory?(combined_path) data_hash[filename] ||= {} data_hash[filename].merge!(import(File.join(path, filename), data_hash[filename])) data_hash[filename].merge!({ "is_directory" => true }) # yaml file elsif filename.end_with?(".yml") without_ext = File.basename(filename, ".yml") yaml_data = YAML.load_file(combined_path) || {} data_hash[without_ext] ||= {} data_hash[without_ext].merge!(yaml_data) data_hash[without_ext].merge!({ "is_yaml" => true }) # markdown file elsif filename.end_with?(".md") without_ext = File.basename(filename, ".md") file = File.open(combined_path, "r") parsed_markdown = self.parse_markdown(file.read) file.close data_hash[without_ext] ||= {} data_hash[without_ext].merge!({ "parsed_markdown" => parsed_markdown }) data_hash[without_ext].merge!({ "is_markdown" => true }) end end data_hash end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
data_processor-0.2.1 | lib/data_processor/import.rb |