Class: Tagomatic::FormatCompiler
- Inherits:
-
Object
- Object
- Tagomatic::FormatCompiler
- Includes:
- Tags
- Defined in:
- lib/tagomatic/format_compiler.rb
Constant Summary
Constants included from Tags
Tags::FORMAT_ID_ALBUM, Tags::FORMAT_ID_ALBUM_AGAIN, Tags::FORMAT_ID_ARTIST, Tags::FORMAT_ID_ARTIST_AGAIN, Tags::FORMAT_ID_DISC, Tags::FORMAT_ID_EXTENDED_WHITESPACE, Tags::FORMAT_ID_GENRE, Tags::FORMAT_ID_IGNORE, Tags::FORMAT_ID_SURROUNDED_YEAR, Tags::FORMAT_ID_TITLE, Tags::FORMAT_ID_TRACKNUM, Tags::FORMAT_ID_WHITESPACE, Tags::FORMAT_ID_YEAR, Tags::FORMAT_REGEXP_ALBUM, Tags::FORMAT_REGEXP_ALBUM_AGAIN, Tags::FORMAT_REGEXP_ARTIST, Tags::FORMAT_REGEXP_ARTIST_AGAIN, Tags::FORMAT_REGEXP_DISC, Tags::FORMAT_REGEXP_EXTENDED_WHITESPACE, Tags::FORMAT_REGEXP_GENRE, Tags::FORMAT_REGEXP_IGNORE, Tags::FORMAT_REGEXP_SURROUNDED_YEAR, Tags::FORMAT_REGEXP_TITLE, Tags::FORMAT_REGEXP_TRACKNUM, Tags::FORMAT_REGEXP_WHITESPACE, Tags::FORMAT_REGEXP_YEAR
Instance Method Summary collapse
- #compile_format(format) ⇒ Object
-
#initialize(format_matcher_factory, logger) ⇒ FormatCompiler
constructor
A new instance of FormatCompiler.
Constructor Details
#initialize(format_matcher_factory, logger) ⇒ FormatCompiler
Returns a new instance of FormatCompiler.
9 10 11 12 |
# File 'lib/tagomatic/format_compiler.rb', line 9 def initialize(format_matcher_factory, logger) @format_matcher_factory = format_matcher_factory @logger = logger end |
Instance Method Details
#compile_format(format) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tagomatic/format_compiler.rb', line 14 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_ARTIST if tag == FORMAT_ID_ARTIST regexp << FORMAT_REGEXP_ARTIST_AGAIN if tag == FORMAT_ID_ARTIST_AGAIN regexp << FORMAT_REGEXP_ALBUM if tag == FORMAT_ID_ALBUM regexp << FORMAT_REGEXP_ALBUM_AGAIN if tag == FORMAT_ID_ALBUM_AGAIN regexp << FORMAT_REGEXP_DISC if tag == FORMAT_ID_DISC regexp << FORMAT_REGEXP_GENRE if tag == FORMAT_ID_GENRE regexp << FORMAT_REGEXP_IGNORE if tag == FORMAT_ID_IGNORE regexp << FORMAT_REGEXP_TRACKNUM if tag == FORMAT_ID_TRACKNUM regexp << FORMAT_REGEXP_TITLE if tag == FORMAT_ID_TITLE regexp << FORMAT_REGEXP_WHITESPACE if tag == FORMAT_ID_WHITESPACE regexp << FORMAT_REGEXP_EXTENDED_WHITESPACE if tag == FORMAT_ID_EXTENDED_WHITESPACE regexp << FORMAT_REGEXP_YEAR if tag == FORMAT_ID_YEAR regexp << FORMAT_REGEXP_SURROUNDED_YEAR if tag == FORMAT_ID_SURROUNDED_YEAR regexp << Regexp.escape(tail) end compiled = Regexp.compile(regexp, Regexp::IGNORECASE) @format_matcher_factory.create_format_matcher(compiled, tag_mapping, format) rescue @logger.error "failed compiling #{format}", $! raise $! end |