module Dump::Snapshot::CleanNParse

Cleanup name of dump

Public Instance Methods

clean_description(description) click to toggle source
# File lib/dump/snapshot.rb, line 160
def clean_description(description)
  clean_str(description, '()#')[0, 50].strip
end
clean_str(str, additional = nil) click to toggle source
# File lib/dump/snapshot.rb, line 156
def clean_str(str, additional = nil)
  str.to_s.strip.gsub(/\s+/, ' ').gsub(/[^A-Za-z0-9 \-_#{Regexp.escape(additional.to_s) if additional}]+/, '_')
end
clean_tag(tag) click to toggle source
# File lib/dump/snapshot.rb, line 164
def clean_tag(tag)
  clean_str(tag).downcase.sub(/^\-+/, '')[0, 20].strip
end
clean_tags(tags) click to toggle source
# File lib/dump/snapshot.rb, line 168
def clean_tags(tags)
  tags.to_s.split(',').map{ |tag| clean_tag(tag) }.uniq.reject(&:blank?).sort
end
get_filter_tags(tags) click to toggle source
# File lib/dump/snapshot.rb, line 172
def get_filter_tags(tags)
  groups = Hash.new{ |hash, key| hash[key] = SortedSet.new }
  tags.to_s.split(',').each do |tag|
    next unless (m = tag.strip.match(/^(\-|\+)?(.*)$/))

    type = {'+' => :mandatory, '-' => :forbidden}[m[1]] || :simple
    next unless (cleaned_tag = clean_tag(m[2])).present?

    groups[type] << cleaned_tag
  end
  [:simple, :mandatory].each do |type|
    if (clashing = (groups[type] & groups[:forbidden])).present?
      fail ArgumentError, "#{type} tags clashes with forbidden ones: #{clashing}"
    end
  end
  groups.each_with_object({}){ |(key, value), hsh| hsh[key] = value.to_a }
end