Sha256: 9e61ac89a99eeef5a3783b91620a63474caf959641b7c9e75f0eb13314e48647
Contents?: true
Size: 999 Bytes
Versions: 11
Compression:
Stored size: 999 Bytes
Contents
# frozen_string_literal: true require 'ostruct' module Evertils class Type attr_reader :params def initialize(path) begin type_path = File.expand_path(path) contents = YAML.load_file(type_path) return if contents.empty? translate_variables(contents) @params = OpenStruct.new(contents) rescue Errno::ENOENT Notify.error("File doesn't exist - #{type_path}") end end private def translate_variables(hash) title_format = hash[:title].dup hash.map do |item| break if item.last.is_a? Hash Evertils::Cfg::REPLACEMENTS.each_pair do |k, v| item.last.gsub!(k.to_s, v.to_s) if item.last.is_a? String item.last.map { |i| break if i.is_a? Hash; i.gsub!(k.to_s, v.to_s) } if item.last.is_a? Array end end hash[:title_format] = title_format unless hash.key? :title_format Evertils::Helper::Formatting.symbolize_keys(hash) end end end
Version data entries
11 entries across 11 versions & 1 rubygems