Class: ImageOptim::BinResolver::ComparableCondition
- Inherits:
-
Object
- Object
- ImageOptim::BinResolver::ComparableCondition
- Defined in:
- lib/image_optim/bin_resolver/comparable_condition.rb
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Class Method Summary collapse
Instance Method Summary collapse
- #===(to_compare) ⇒ Object
-
#initialize(method, *args) ⇒ ComparableCondition
constructor
A new instance of ComparableCondition.
- #to_s ⇒ Object
Constructor Details
#initialize(method, *args) ⇒ ComparableCondition
Returns a new instance of ComparableCondition.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/image_optim/bin_resolver/comparable_condition.rb', line 17 def initialize(method, *args) @method = method.to_sym @args = args case @method when :between? raise ArgumentError, "`between?' expects 2 arguments" unless args.length == 2 when :<, :<=, :==, :>, :>= raise ArgumentError, "`#{method}' expects 1 argument" unless args.length == 1 else raise ArgumentError, "Unknown method `#{method}'" end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
16 17 18 |
# File 'lib/image_optim/bin_resolver/comparable_condition.rb', line 16 def args @args end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
16 17 18 |
# File 'lib/image_optim/bin_resolver/comparable_condition.rb', line 16 def method @method end |
Class Method Details
Instance Method Details
#===(to_compare) ⇒ Object
31 32 33 |
# File 'lib/image_optim/bin_resolver/comparable_condition.rb', line 31 def ===(to_compare) to_compare.send(@method, *@args) end |
#to_s ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/image_optim/bin_resolver/comparable_condition.rb', line 35 def to_s if @method == :between? @args.join('..') else "#{@method} #{@args.first}" end end |