Sha256: 48a0ff796315d3dee3224717138eb1c7e15e1eb1999fd18829d50b23a25de893
Contents?: true
Size: 1.15 KB
Versions: 53
Compression:
Stored size: 1.15 KB
Contents
module Picky # Collection class for qualifiers. # class QualifierMapper attr_reader :mapping # # def initialize categories @mapping = {} categories.each { |category| add category } end # # def add category category.qualifiers.each do |qualifier| sym_qualifier = qualifier.intern Picky.logger.warn %Q{Warning: Qualifier "#{qualifier}" already mapped to category #{mapping[sym_qualifier].identifier} (ambiguous qualifier mapping).} if mapping.has_key? sym_qualifier mapping[sym_qualifier] = category end end # Normalizes the given qualifier. # # Returns nil if it is not allowed, the normalized qualifier if it is. # def map qualifier return nil if qualifier.empty? mapping[qualifier.intern] end # Restricts the given categories. # def restrict user_qualified if @restricted user_qualified ? @restricted & user_qualified : @restricted else user_qualified end end def restrict_to *qualifiers @restricted = qualifiers.map { |qualifier| map qualifier }.compact end end end
Version data entries
53 entries across 53 versions & 1 rubygems