Module: Cardname::Predicates

Included in:
Cardname
Defined in:
cardname/lib/cardname/predicates.rb

Instance Method Summary collapse

Instance Method Details

#compound?Boolean Also known as: junction?

Returns true if name has more than one part.

Returns:

  • (Boolean)

    true if name has more than one part



9
10
11
# File 'cardname/lib/cardname/predicates.rb', line 9

def compound?
  !simple?
end

#ends_with_parts?(*suffix) ⇒ Boolean Also known as: end_with_parts?

Returns true if name ends with the same parts as prefix.

Returns:

  • (Boolean)

    true if name ends with the same parts as prefix



30
31
32
33
# File 'cardname/lib/cardname/predicates.rb', line 30

def ends_with_parts? *suffix
  end_name = suffix.to_name
  end_name == self[-end_name.num_parts..-1]
end

#include?(subname) ⇒ Boolean

Returns true if name has a chain of parts that equals subname.

Returns:

  • (Boolean)

    true if name has a chain of parts that equals subname



37
38
39
40
# File 'cardname/lib/cardname/predicates.rb', line 37

def include? subname
  subkey = subname.to_name.key
  key =~ /(^|#{JOINT_RE})#{Regexp.quote subkey}($|#{JOINT_RE})/
end

#simple?Boolean Also known as: simple

Returns:

  • (Boolean)


3
4
5
# File 'cardname/lib/cardname/predicates.rb', line 3

def simple?
  @simple.nil? ? (@simple = parts.size <= 1) : @simple
end

#starts_with_parts?(*prefix) ⇒ Boolean Also known as: start_with_parts?

Returns true if name starts with the same parts as prefix.

Returns:

  • (Boolean)

    true if name starts with the same parts as prefix



23
24
25
26
# File 'cardname/lib/cardname/predicates.rb', line 23

def starts_with_parts? *prefix
  start_name = prefix.to_name
  start_name == self[0, start_name.num_parts]
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'cardname/lib/cardname/predicates.rb', line 14

def valid?
  return true if self.class.nothing_banned?

  !parts.find do |pt|
    pt.match self.class.banned_re
  end
end