Sha256: 8babf6bda03d92b66660220d336577dee8f9524dc9220dc9affa1ecb8e2772b2

Contents?: true

Size: 784 Bytes

Versions: 3

Compression:

Stored size: 784 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]
        if value
          value = value.gsub('_', ' ')
          parts = value.split(' ')
          capitalized = parts.map {|p| p.capitalize}
          value = capitalized.join(' ')
        end
        tags[@mapping[index]] = value
      end
      tags
    end

    def to_s
      @format
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tagomatic-0.1.0 lib/tagomatic/format_matcher.rb
tagomatic-0.0.3 lib/tagomatic/format_matcher.rb
tagomatic-0.0.2 lib/tagomatic/format_matcher.rb