module NRB::Support::BrandNameParser

Public Instance Methods

parse_brand_name(string, brand_class: String) click to toggle source
# File lib/nrb/support/brand_name_parser.rb, line 26
def parse_brand_name(string, brand_class: String)
  return nil if string.nil?
  matched = match_brand_name(string)
  return brand_class.new(matched) if matched
end

Private Instance Methods

brands_with_expressions() click to toggle source
# File lib/nrb/support/brand_name_parser.rb, line 34
def brands_with_expressions
  self.class.brands_with_expressions
end
match_brand_name(string) click to toggle source
# File lib/nrb/support/brand_name_parser.rb, line 39
def match_brand_name(string)
  matches = brands_with_expressions.each_pair.find do |name,exp|
              string =~ exp
            end
  matches.nil? ? '' : matches.first
end