module FaviconParty::Utils
Public Instance Methods
encode_utf8(text)
click to toggle source
# File lib/favicon_party/utils.rb, line 22 def encode_utf8(text) return text if text.valid_encoding? text.encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => '') end
get_mime_type(data, use_file_cmd = true)
click to toggle source
# File lib/favicon_party/utils.rb, line 27 def get_mime_type(data, use_file_cmd = true) if use_file_cmd with_temp_data_file(data) {|t| `file -b --mime-type #{t.path.to_s}`.strip } else FileMagic.new(:mime_type).buffer(data) end end
prefix_url(url, options = {})
click to toggle source
# File lib/favicon_party/utils.rb, line 9 def prefix_url(url, options = {}) unless options[:downcase] == false url = URI.encode url.strip.downcase else url = URI.encode url.strip end if url =~ /https?:\/\// url else "http://#{url}" end end
with_temp_data_file(data, &block)
click to toggle source
# File lib/favicon_party/utils.rb, line 35 def with_temp_data_file(data, &block) begin t = Tempfile.new(["favicon", ".ico"]) t.binmode t.write data t.close result = block.call(t) ensure t.unlink end result end