Module: RScale
- Extended by:
- UUID
- Defined in:
- lib/rscale/uuid.rb,
lib/rscale/errors.rb,
lib/rscale/format.rb,
lib/rscale/rscale.rb,
lib/rscale/processor.rb,
lib/rscale/configuration.rb
Defined Under Namespace
Modules: Processor, UUID Classes: ConfigError, Configuration, Format, FormatError, ProcessingError
Constant Summary collapse
- @@config =
nil
- @@formats =
{}
Class Method Summary collapse
-
.config ⇒ Object
Get current RScale configuration.
-
.configure {|@@config| ... } ⇒ Object
Configure RScale.
-
.format(name) ⇒ Object
Add new format.
-
.formats ⇒ Object
Get list of formats.
-
.image_for(format, file) ⇒ Object
Generate thumbnails for the image format.
Methods included from UUID
Class Method Details
.config ⇒ Object
Get current RScale configuration
14 15 16 |
# File 'lib/rscale/rscale.rb', line 14 def self.config @@config end |
.configure {|@@config| ... } ⇒ Object
Configure RScale
8 9 10 11 |
# File 'lib/rscale/rscale.rb', line 8 def self.configure @@config = Configuration.new if @@config.nil? yield @@config end |
.format(name) ⇒ Object
Add new format
19 20 21 22 23 24 25 26 |
# File 'lib/rscale/rscale.rb', line 19 def self.format(name) unless @@formats.key?(name) @@formats[name] = Format.new(name) yield @@formats[name] if block_given? else raise FormatError, "Format with name [#{name.to_s}] is already defined" end end |
.formats ⇒ Object
Get list of formats
29 30 31 |
# File 'lib/rscale/rscale.rb', line 29 def self.formats @@formats end |
.image_for(format, file) ⇒ Object
Generate thumbnails for the image format
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rscale/rscale.rb', line 34 def self.image_for(format, file) if @@formats.key?(format.to_sym) fmt = @@formats[format.to_sym] file_info = File.get_info(file) url = fmt.url image = {} = file_info.merge(:format => fmt.name) [:time] = Time.now.to_i unless url[':time'].nil? [:md5] = Digest::MD5.filedigest(file) unless url[':md5'].nil? unless url[':uuid'].nil? [:uuid] = uuid [:uuid_dir] = "#{[:uuid][0,2]}/#{[:uuid][2,2]}" end fmt.styles.each_pair do |k,v| url = fmt.url.placeholders(.merge(v)) file_out = @@config.public + "/#{url}" if Processor.process(file, file_out, v) image[k] = url end end return image.size == fmt.styles.size ? image : nil else raise ArgumentError, "Format #{format.to_s} cannot be found!" end end |