Module: Cardname::Predicates
- Included in:
- Cardname
- Defined in:
- lib/cardname/predicates.rb
Instance Method Summary collapse
- #blank? ⇒ Boolean (also: #empty?)
-
#ends_with?(postfix) ⇒ Boolean
(also: #end_with?)
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?(prefix) ⇒ Boolean
(also: #start_with?)
True if name starts with the same parts as ‘prefix`.
- #valid? ⇒ Boolean
Instance Method Details
#blank? ⇒ Boolean Also known as: empty?
8 9 10 |
# File 'lib/cardname/predicates.rb', line 8 def blank? s.blank? end |
#ends_with?(postfix) ⇒ Boolean Also known as: end_with?
Returns true if name ends with the same parts as ‘prefix`.
27 28 29 30 |
# File 'lib/cardname/predicates.rb', line 27 def ends_with? postfix end_name = postfix.to_name end_name == self[-end_name.length..-1] end |
#include?(subname) ⇒ Boolean
Returns true if name has a chain of parts that equals ‘subname`.
34 35 36 37 |
# File 'lib/cardname/predicates.rb', line 34 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?(prefix) ⇒ Boolean Also known as: start_with?
Returns true if name starts with the same parts as ‘prefix`.
20 21 22 23 |
# File 'lib/cardname/predicates.rb', line 20 def starts_with? prefix start_name = prefix.to_name start_name == self[0, start_name.length] end |
#valid? ⇒ Boolean
13 14 15 16 17 |
# File 'lib/cardname/predicates.rb', line 13 def valid? !parts.find do |pt| pt.match self.class.banned_re end end |