Class: Kinu::Geometry
- Inherits:
-
Object
- Object
- Kinu::Geometry
- Defined in:
- lib/kinu/geometry.rb
Constant Summary collapse
- AVAILABLE_TYPES =
{ width: :w, height: :h, quality: :q, crop: :c, manual_crop: :mc, width_offset: :wo, height_offset: :ho, crop_width: :cw, crop_height: :ch, assumption_width: :aw, original: :o, middle: :m, }.freeze
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(options) ⇒ Geometry
constructor
A new instance of Geometry.
- #to_s ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(options) ⇒ Geometry
Returns a new instance of Geometry.
18 19 20 21 |
# File 'lib/kinu/geometry.rb', line 18 def initialize() @options = validate end |
Instance Method Details
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/kinu/geometry.rb', line 38 def empty? @options.empty? end |
#to_s ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/kinu/geometry.rb', line 42 def to_s geo = [] AVAILABLE_TYPES.each do |full_name, short_name| next if @options[full_name].nil? geo << "#{short_name}=#{@options[full_name]}" end geo.join(',') end |
#validate ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kinu/geometry.rb', line 23 def validate raise ArgumentError, "required geometry hash." if empty? return if !(@options[:width].nil? && @options[:height].nil?) return if @options[:middle] == true return if @options[:original] == true raise ArgumentError, <<-EOS invalid geometry, geometry must be met least one condition. - set width or height any numeric. - set middle true. - set original true. EOS end |