Module: Esvg::Utils
Instance Method Summary collapse
- #attributes(hash) ⇒ Object
- #compress(file) ⇒ Object
- #dasherize(input) ⇒ Object
- #sort(hash) ⇒ Object
- #sub_path(root, path) ⇒ Object
Instance Method Details
#attributes(hash) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/esvg/utils.rb', line 11 def attributes(hash) att = [] hash.each do |key, value| att << %Q{#{key.to_s.gsub(/_/,'-')}="#{value}"} unless value.nil? end att.join(' ') end |
#compress(file) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/esvg/utils.rb', line 27 def compress(file) mtime = File.mtime(file) gz_file = "#{file}.gz" return if (File.exist?(gz_file) && File.mtime(gz_file) >= mtime) File.open(gz_file, "wb") do |dest| gz = ::Zlib::GzipWriter.new(dest, Zlib::BEST_COMPRESSION) gz.mtime = mtime.to_i IO.copy_stream(open(file), gz) gz.close end File.utime(mtime, mtime, gz_file) gz_file end |
#dasherize(input) ⇒ Object
3 4 5 |
# File 'lib/esvg/utils.rb', line 3 def dasherize(input) Esvg.dasherize(input) end |
#sort(hash) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/esvg/utils.rb', line 19 def sort(hash) sorted = {} hash.sort.each do |h| sorted[h.first] = h.last end sorted end |