Sha256: 4ecab8b564373cda1caa127972a5ccf578a1f4b315185a112fc06146c510bba2
Contents?: true
Size: 1.36 KB
Versions: 19
Compression:
Stored size: 1.36 KB
Contents
# coding: utf-8 module Query # A single qualifier. # class Qualifier attr_reader :normalized_qualifier, :codes # # # codes is an array. # def initialize normalized_qualifier, codes @normalized_qualifier = normalized_qualifier @codes = codes.map &:to_sym end # Will overwrite if the key is present in the hash. # def inject_into hash codes.each do |code| hash[code] = normalized_qualifier end end end # Collection class for qualifiers. # class Qualifiers include Singleton attr_reader :qualifiers, :normalization_mapping delegate :<<, :to => :qualifiers # # def initialize @qualifiers = [] @normalization_mapping = {} end # TODO Spec. # def self.add name, qualifiers instance << Qualifier.new(name, qualifiers) end # Uses the qualifiers to prepare (optimize) the qualifier handling. # def prepare qualifiers.each do |qualifier| qualifier.inject_into normalization_mapping end end # Normalizes the given qualifier. # # Returns nil if it is not allowed, the normalized qualifier if it is. # # Note: Normalizes. # def normalize qualifier return nil if qualifier.blank? normalization_mapping[qualifier.to_sym] end end end
Version data entries
19 entries across 19 versions & 1 rubygems