Module: PhotoCook::Command

Included in:
PhotoCook
Defined in:
lib/photo-cook/command.rb

Instance Method Summary collapse

Instance Method Details

#assemble_command(width, height, pixel_ratio, crop) ⇒ Object

NOTE: This method performs no validation



19
20
21
22
23
24
# File 'lib/photo-cook/command.rb', line 19

def assemble_command(width, height, pixel_ratio, crop)
  "width=#{  width  == 0 ? 'auto' : width}&" +
  "height=#{ height == 0 ? 'auto' : height}&" +
  "pixel_ratio=#{pixel_ratio.ceil}&" +
  "crop=#{   bool_to_crop(crop)}&"
end

#bool_to_crop(crop) ⇒ Object



30
31
32
# File 'lib/photo-cook/command.rb', line 30

def bool_to_crop(crop)
  crop ? 'yes' : 'no'
end

#command_regexObject



9
10
11
12
13
14
15
16
# File 'lib/photo-cook/command.rb', line 9

def command_regex
  @command_regex ||= %r{
      width=       (?<width>      auto|\d{1,4}) &
      height=      (?<height>     auto|\d{1,4}) &
      pixel_ratio= (?<pixel_ratio>[1234]) &
      crop=        (?<crop>       yes|no)
    }x
end

#crop_to_bool(crop) ⇒ Object



26
27
28
# File 'lib/photo-cook/command.rb', line 26

def crop_to_bool(crop)
  crop == 'yes'
end