Sha256: 8d206d7bd5c2016ab16e7984750583f71a3b4947e2398983340edc2bd749fc4b
Contents?: true
Size: 822 Bytes
Versions: 5
Compression:
Stored size: 822 Bytes
Contents
module Tagomatic class FormatMatcher def initialize(compiled_regexp, tag_mapping, original_format) @regexp = compiled_regexp @mapping = tag_mapping @format = original_format end def match(file_path) matchdata = @regexp.match(file_path) return nil unless matchdata return nil unless matchdata.captures.size == @mapping.size tags = {} 0.upto(@mapping.size) do |index| value = matchdata.captures[index] value = normalize(value) if value tags[@mapping[index]] = value end tags end def to_s @format end protected def normalize(value) value = value.gsub('_', ' ') parts = value.split(' ') capitalized = parts.map {|p| p.capitalize} capitalized.join(' ') end end end
Version data entries
5 entries across 5 versions & 1 rubygems