class Evertils::Type

Attributes

params[R]

Public Class Methods

new(path) click to toggle source
# File lib/evertils/type.rb, line 9
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 Instance Methods

translate_variables(hash) click to toggle source
# File lib/evertils/type.rb, line 26
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