Module: Cardname::Predicates
- Included in:
- Cardname
- Defined in:
- lib/cardname/predicates.rb
Instance Method Summary collapse
-
#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`.
-
#junction? ⇒ Boolean
True if name has more than one part.
-
#starts_with_parts?(*prefix) ⇒ Boolean
(also: #start_with_parts?)
True if name starts with the same parts as ‘prefix`.
- #valid? ⇒ Boolean
Instance Method Details
#ends_with_parts?(*suffix) ⇒ Boolean Also known as: end_with_parts?
Returns true if name ends with the same parts as ‘prefix`.
22 23 24 25 |
# File 'lib/cardname/predicates.rb', line 22 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`.
29 30 31 32 |
# File 'lib/cardname/predicates.rb', line 29 def include? subname subkey = subname.to_name.key key =~ /(^|#{JOINT_RE})#{Regexp.quote subkey}($|#{JOINT_RE})/ end |
#junction? ⇒ Boolean
Returns true if name has more than one part.
4 5 6 |
# File 'lib/cardname/predicates.rb', line 4 def junction? !simple? end |
#starts_with_parts?(*prefix) ⇒ Boolean Also known as: start_with_parts?
Returns true if name starts with the same parts as ‘prefix`.
15 16 17 18 |
# File 'lib/cardname/predicates.rb', line 15 def starts_with_parts? *prefix start_name = prefix.to_name start_name == self[0, start_name.num_parts] end |
#valid? ⇒ Boolean
8 9 10 11 12 |
# File 'lib/cardname/predicates.rb', line 8 def valid? !parts.find do |pt| pt.match self.class.banned_re end end |