module Emojidex::Data::EmojiComponentSetAssetInformation

Asset information for emoji

Attributes

checksums[RW]
paths[RW]
remote_checksums[RW]

Public Instance Methods

blank_checksums() click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 54
def blank_checksums
  @checksums = generate_blank_entry_set
  @remote_checksums = generate_blank_entry_set
end
blank_paths() click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 34
def blank_paths
  @paths = generate_blank_path_set
end
fill_paths(paths) click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 48
def fill_paths(paths)
  @paths = paths
  @paths[:svg].slice!(/\.svg$/)
  @paths[:png].each { |png| png.slice!(/\.png$/) }
end
fill_remote_checksums(checksums) click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 82
def fill_remote_checksums(checksums)
  #todo once implemented in API
end
generate_blank_entry_set() click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 16
def generate_blank_entry_set
  entry_set = []
  @components.each do |component_set|
    component_group = {}
    component_set.each do |single_component|
      next if single_component == ''
      component_group[single_component] = {}
      component_group[single_component][:svg] = nil
      component_group[single_component][:png] = {}
      Emojidex::Defaults.sizes.keys.each do |size|
        component_group[single_component][:png][size] = nil
      end
    end
    entry_set << component_group
  end
  entry_set
end
generate_blank_path_set() click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 38
def generate_blank_path_set
  paths = {}
  paths[:svg] = nil
  paths[:png] = {}
  Emojidex::Defaults.sizes.keys.each do |size|
    paths[:png][size] = nil
  end
  paths
end
generate_checksum(component_set_num, component_name, format, size = nil) click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 59
def generate_checksum(component_set_num, component_name, format, size = nil)
  case format
  when :png
    return @checksums[component_set_num][component_name][:png][size] =
      _checksum_for_file("#{@paths[:png][size]}/#{component_set_num}/#{component_name}.png")
  when :svg
    return @checksums[component_set_num][component_name][:svg] =
      _checksum_for_file("#{@paths[:svg]}/#{component_set_num}/#{component_name}.svg")
  end
  nil
end
generate_checksums() click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 71
def generate_checksums
  @components.each_with_index do |component_set, i|
    component_set.each do |component_name|
      generate_checksum(i, component_name, :svg)
      @checksums[i][component_name][:png].keys.each do |size_key|
        generate_checksum(i, component_name, :png, size_key)
      end
    end
  end
end
init_asset_info(details = {}) click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 10
def init_asset_info(details = {})
  blank_paths
  blank_checksums
  fill_remote_checksums(details[:checksums]) if details.include? :checksums
end

Private Instance Methods

_checksum_for_file(path) click to toggle source
# File lib/emojidex/data/emoji/component_set_asset_information.rb, line 88
def _checksum_for_file(path)
  (File.exist? path) ? Digest::MD5.file(path).hexdigest : nil
end