Class: Bemer::Predicate

Inherits:
Object
  • Object
show all
Defined in:
lib/bemer/predicate.rb

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Predicate

Returns a new instance of Predicate.



5
6
7
8
9
10
11
12
13
# File 'lib/bemer/predicate.rb', line 5

def initialize(**options)
  @block     = options[:block]
  @condition = options[:condition].nil? ? true : options[:condition]
  @element   = options[:elem]
  @mask      = build_mask(options[:block], options[:elem])
  @mixins    = Mixes.new(options[:mix])
  @modifiers = ModifierList.new(:block, :elem, options[:mods])
  @wildcard  = nil
end

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/bemer/predicate.rb', line 15

def match?(node)
  condition?(node) && mix?(node.mix) && mods?(node.mods)
end

#name_match?(name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/bemer/predicate.rb', line 19

def name_match?(name)
  Bemer.can_use_new_matcher? ? mask.match?(name) : mask =~ name
end

#wildcard?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/bemer/predicate.rb', line 23

def wildcard?
  return wildcard unless wildcard.nil?

  @wildcard = name.include?('*')
end