Class: Magick::Targeting::CustomAttribute
- Defined in:
- lib/magick/targeting/custom_attribute.rb
Instance Method Summary collapse
-
#initialize(attribute_name, values, operator: :equals) ⇒ CustomAttribute
constructor
A new instance of CustomAttribute.
- #matches?(context) ⇒ Boolean
Constructor Details
#initialize(attribute_name, values, operator: :equals) ⇒ CustomAttribute
Returns a new instance of CustomAttribute.
6 7 8 9 10 |
# File 'lib/magick/targeting/custom_attribute.rb', line 6 def initialize(attribute_name, values, operator: :equals) @attribute_name = attribute_name.to_sym @values = Array(values) @operator = operator.to_sym end |
Instance Method Details
#matches?(context) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/magick/targeting/custom_attribute.rb', line 12 def matches?(context) context_value = context[@attribute_name] || context[@attribute_name.to_s] return false if context_value.nil? case @operator when :equals, :eq @values.include?(context_value.to_s) when :not_equals, :ne !@values.include?(context_value.to_s) when :in @values.include?(context_value.to_s) when :not_in !@values.include?(context_value.to_s) when :greater_than, :gt context_value.to_f > @values.first.to_f when :less_than, :lt context_value.to_f < @values.first.to_f else false end end |