lib/compressible/readable.rb in compressible-0.0.2.3 vs lib/compressible/readable.rb in compressible-0.0.2.4

- old
+ new

@@ -42,14 +42,10 @@ assets = cache_environments.include?(environment) ? keys : send("uncached_#{type.to_s}_paths", *keys) assets end - def read(type, from) - IO.read(path_for(type, from)) - end - def asset_name(path) result = path.to_s.split(".") if result.last =~ /(js|css)/ result = result[0..-2].join(".") else @@ -71,9 +67,27 @@ end path << ".#{KEYS[type].to_s}" unless path.split(".").last == KEYS[type].to_s path + end + + def size(type, *paths) + result = paths.collect { |path| File.size(path_for(type, path)) }.inject(0) { |sum, x| sum + x } + by = "kb" + unless result <= 0 + result = case by + when "kb" + result / 1_000 + when "mb" + result / 1_000_000 + end + end + return "#{result.to_s}#{by}" + end + + def read(type, from) + IO.read(path_for(type, from)) end end end end \ No newline at end of file