Class: HashConditions::ModuleMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_conditions/module_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, replacement, operations = []) ⇒ ModuleMatcher



5
6
7
8
9
10
11
# File 'lib/hash_conditions/module_matcher.rb', line 5

def initialize matcher, replacement, operations = []
  operations = [ :parse, :match ] if operations.empty?

  @matcher = matcher
  @replacement = replacement
  @operations = operations
end

Instance Attribute Details

#replacementObject

Returns the value of attribute replacement.



3
4
5
# File 'lib/hash_conditions/module_matcher.rb', line 3

def replacement
  @replacement
end

Instance Method Details

#apply_for(key, condition) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/hash_conditions/module_matcher.rb', line 17

def apply_for key, condition
  case @matcher
    when Symbol then @matcher == key.to_sym
    when String then @matcher == key.to_s
    when Regexp then @matcher =~ key.to_s
    when Proc   then !! @matcher.call( key, condition )
    else false
  end
end

#for_operation?(operation) ⇒ Boolean



13
14
15
# File 'lib/hash_conditions/module_matcher.rb', line 13

def for_operation? operation
  @operations.include? operation
end