class ImageFlux::Option
Constants
- ALLOWED_FORMATS
output attributes ref: console.imageflux.jp/docs/image/conversion-parameters#output
- ALLOWED_ROTATES
rotation attributes ref: console.imageflux.jp/docs/image/conversion-parameters#rotation
- ALLOWED_THROUGH_FORMATS
through attributes console.imageflux.jp/docs/image/conversion-parameters#through
- REGEXP_BLUR
- REGEXP_FLOAT
- REGEXP_INTEGER
- REGEXP_MASK
- REGEXP_UNSHARP
Public Class Methods
attribute(name, type, options = {}, &block)
click to toggle source
# File lib/image_flux/option.rb, line 23 def self.attribute(name, type, options = {}, &block) attribute = ImageFlux::Attribute.new(name, type, **options) attribute.instance_eval(&block) if block_given? key_pairs[attribute.name] = attribute attribute.aliases.each do |key| key_pairs[key] = attribute end names = [name] + (options[:aliases] || []) names.each do |n| define_method(:"#{n}") { @values[attribute] } define_method(:"#{n}=") { |val| @values[attribute] = val } end attributes.push(attribute) end
attributes()
click to toggle source
# File lib/image_flux/option.rb, line 15 def self.attributes @attributes ||= [] end
key_pairs()
click to toggle source
# File lib/image_flux/option.rb, line 19 def self.key_pairs @key_pairs ||= {} end
new(options = {})
click to toggle source
# File lib/image_flux/option.rb, line 191 def initialize(options = {}) @values = {} options.each_pair do |key, val| key = key.to_s.to_sym attribute = self.class.key_pairs[key] @values[attribute] = val if attribute end end
Public Instance Methods
merge(other)
click to toggle source
# File lib/image_flux/option.rb, line 227 def merge(other) to_h.merge(other) end
prefix_path()
click to toggle source
# File lib/image_flux/option.rb, line 201 def prefix_path prefix_attr = self.class.key_pairs[:prefix] @values[prefix_attr] end
to_h()
click to toggle source
# File lib/image_flux/option.rb, line 219 def to_h hash = {} @values.each_pair do |attribute, val| hash[attribute.name] = val end hash end
to_query()
click to toggle source
# File lib/image_flux/option.rb, line 206 def to_query errors = [] queries = @values.to_a.map do |pair| attribute = pair.first value = pair.last errors.concat(attribute.validate!(value)) attribute.querize(value) end raise ImageFlux::InvalidOptionError, errors.join(', ') unless errors.length.zero? queries.reject(&:nil?).join(',') end