Class: ImageOptim::BinResolver::ComparableCondition

Inherits:
Object
  • Object
show all
Defined in:
lib/image_optim/bin_resolver/comparable_condition.rb

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#argsObject (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

#methodObject (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

.isObject



12
13
14
# File 'lib/image_optim/bin_resolver/comparable_condition.rb', line 12

def self.is
  Builder.new
end

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_sObject



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