Module: Cardname::Predicates
- Included in:
- Cardname
- Defined in:
- cardname/lib/cardname/predicates.rb
Overview
name methods returning true/false
Instance Method Summary collapse
-
#compound? ⇒ Boolean
true if name has more than one part.
-
#ends_with_parts?(*suffix) ⇒ Boolean
(also: #end_with_parts?)
true if name ends with the same parts as
prefix
. -
#include?(subname) ⇒ Boolean
true if name has a chain of parts that equals
subname
. -
#simple? ⇒ Boolean
true if name has only one part.
-
#starts_with_joint? ⇒ Boolean
+X.
-
#starts_with_parts?(*prefix) ⇒ Boolean
(also: #start_with_parts?)
true if name starts with the same parts as
prefix
. -
#valid? ⇒ Boolean
true unless name contains banned characters.
Instance Method Details
#compound? ⇒ Boolean
true if name has more than one part
13 14 15 |
# File 'cardname/lib/cardname/predicates.rb', line 13 def compound? !simple? end |
#ends_with_parts?(*suffix) ⇒ Boolean Also known as: end_with_parts?
true if name ends with the same parts as prefix
43 44 45 46 |
# File 'cardname/lib/cardname/predicates.rb', line 43 def ends_with_parts? *suffix end_name = suffix.to_name end_name == self[-end_name.num_parts..-1] end |
#include?(subname) ⇒ Boolean
true if name has a chain of parts that equals subname
51 52 53 54 |
# File 'cardname/lib/cardname/predicates.rb', line 51 def include? subname subkey = subname.to_name.key key =~ /(^|#{JOINT_RE})#{Regexp.quote subkey}($|#{JOINT_RE})/ end |
#simple? ⇒ Boolean
true if name has only one part
6 7 8 9 |
# File 'cardname/lib/cardname/predicates.rb', line 6 def simple? part_names if @simple.nil? @simple end |
#starts_with_joint? ⇒ Boolean
+X
29 30 31 |
# File 'cardname/lib/cardname/predicates.rb', line 29 def starts_with_joint? compound? && parts.first.empty? end |
#starts_with_parts?(*prefix) ⇒ Boolean Also known as: start_with_parts?
true if name starts with the same parts as prefix
35 36 37 38 |
# File 'cardname/lib/cardname/predicates.rb', line 35 def starts_with_parts? *prefix start_name = prefix.to_name start_name == self[0, start_name.num_parts] end |
#valid? ⇒ Boolean
true unless name contains banned characters
19 20 21 22 23 24 25 |
# File 'cardname/lib/cardname/predicates.rb', line 19 def valid? return true if self.class.nothing_banned? !parts.find do |pt| pt.match self.class.banned_re end end |