Sha256: afaf030390df419923bf9afb7d1a10baaf88027e6a550bae022292e2cd8180aa
Contents?: true
Size: 1.55 KB
Versions: 3
Compression:
Stored size: 1.55 KB
Contents
module Tagomatic class FormatCompiler FORMAT_REGEXP_ARTIST = '([^\/]+)' FORMAT_REGEXP_ALBUM = '([^\/]+)' FORMAT_REGEXP_DISC = '([0-9]+)' FORMAT_REGEXP_GENRE = '([^\/]+)' FORMAT_REGEXP_IGNORE = '([^\/]+)' FORMAT_REGEXP_TITLE = '([^\/]+)' FORMAT_REGEXP_TRACKNUM = '([0-9]+)' FORMAT_REGEXP_YEAR = '([0-9]+)' def initialize(format_matcher_factory) @format_matcher_factory = format_matcher_factory end def compile_format(format) parts = format.split('%') prefix = parts.shift tag_mapping = [] regexp = Regexp.escape(prefix) parts.each do |tag_and_tail| tag = tag_and_tail[0, 1] tail = tag_and_tail[1..-1] tag_mapping << tag regexp << FORMAT_REGEXP_ALBUM if tag == Tagomatic::Tagger::FORMAT_ID_ALBUM regexp << FORMAT_REGEXP_ARTIST if tag == Tagomatic::Tagger::FORMAT_ID_ARTIST regexp << FORMAT_REGEXP_DISC if tag == Tagomatic::Tagger::FORMAT_ID_DISC regexp << FORMAT_REGEXP_GENRE if tag == Tagomatic::Tagger::FORMAT_ID_GENRE regexp << FORMAT_REGEXP_IGNORE if tag == Tagomatic::Tagger::FORMAT_ID_IGNORE regexp << FORMAT_REGEXP_TITLE if tag == Tagomatic::Tagger::FORMAT_ID_TITLE regexp << FORMAT_REGEXP_TRACKNUM if tag == Tagomatic::Tagger::FORMAT_ID_TRACKNUM regexp << FORMAT_REGEXP_YEAR if tag == Tagomatic::Tagger::FORMAT_ID_YEAR regexp << Regexp.escape(tail) end compiled = Regexp.compile(regexp) @format_matcher_factory.create_format_matcher(compiled, tag_mapping, format) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tagomatic-0.1.0 | lib/tagomatic/format_compiler.rb |
tagomatic-0.0.3 | lib/tagomatic/format_compiler.rb |
tagomatic-0.0.2 | lib/tagomatic/format_compiler.rb |