Created
November 27, 2014 20:23
-
-
Save macool/4f0590ac93a7d136e0e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def material_pictograms_for_region(region) | |
return "" unless material.pictograms_of(region).present? | |
hazard_pictograms = [] | |
pictograms_path = Rails.root.join("app/assets/images/hazard-pictograms/") | |
image_names = Dir[pictograms_path + "*.png"].map { |f| f.split("/").last } | |
image_names.map! {|n| File.basename(n,File.extname(n)) } # remove png extension | |
image_names = image_names.sort.reverse # so that we select latest coincidence | |
material.pictograms_of(region).map { |pic| | |
pic.image_name if pic.image_name.present? | |
}.compact.map { |pictogram_name| | |
image_names.detect { |name| Regexp.new(name).match(pictogram_name) } | |
}.compact.each { |image_name| | |
path = Rails.root.join("app/assets/images/hazard-pictograms/" + image_name + ".png") | |
hazard_pictograms << Base64.encode64(open(path) { |io| io.read }) | |
} | |
hazard_pictograms.map do |pictogram| | |
{ | |
region + "-pictogram.image" => pictogram | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment