class Metas::Main

Attributes

controller[R]
default_values[R]
options[R]
values[R]

Public Class Methods

new(controller) click to toggle source
# File lib/metas/main.rb, line 8
def initialize(controller)
  @controller = controller
  @values = controller.default_meta_tags
  @default_values = default_values_social
  @options = YAML.load_file(Rails.root.join('config/metas.yml')).deep_symbolize_keys[:metas]
end

Public Instance Methods

normalize() click to toggle source
# File lib/metas/main.rb, line 15
def normalize
  ignore_keys = default_values.keys
  all_tags_included = insert_all(values)

  all_tags_included.each_with_object({}) do |(social, tags), hsh|
    next if ignore_keys.include?(social)

    hsh[social] = tags
  end
end

Private Instance Methods

default_values_social() click to toggle source
# File lib/metas/main.rb, line 28
def default_values_social
  values.each_with_object({}) do |(key, value), hsh|
    next if value.kind_of? Hash

    hsh[key] = value
  end
end
insert_all(meta_tags) click to toggle source
# File lib/metas/main.rb, line 36
def insert_all(meta_tags)
  meta_tags.each_with_object({}) do |(key, tags), hsh|
    if tags.kind_of?(Hash)
      hsh[key] = tags

      default_values.each do |key_social, value_social|
        next unless options[:same][key_social]
        correct_key = options[:same][key_social][key].to_sym

        hsh[key][correct_key] = value_social
      end
    else
      hsh[key] = tags
    end
  end
end