Sha256: 8666af8329de4dc6afb0b50e1eed090b2aec35ddb5226e3e82ece952c4183bde

Contents?: true

Size: 915 Bytes

Versions: 12

Compression:

Stored size: 915 Bytes

Contents

#! /usr/bin/env ruby
#
# Alphabetizes entries in the domains.txt file
#
# usage: script/alphabetize

require_relative "../lib/gman"

# Read in existing list
domains = File.open(Gman.list_path).read
domains = domains.gsub /\r\n?/, "\n" #normalize line endings
domains = domains.split("\n")

# Split list into grouped hash
group = ""
domain_hash = {}
domains.each do |line|
  next if line.empty?
  if match = /\/\/[\/\s]*(.*)$/i.match(line)
    group = match[1]
  else
    domain_hash[group] = [] if domain_hash[group].nil?
    domain_hash[group].push line.downcase
  end
end

# Sort by groups
domain_hash = domain_hash.sort_by { |k,v| k.downcase }.to_h

# Sort within groups
domain_hash.each do |group, domains|
  domain_hash[group].sort!
end

output = ""
domain_hash.each do |group, domains|
  output << "// #{group}\n"
  output << domains.join("\n")
  output << "\n\n"
end

File.write Gman.list_path, output.strip

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gman-4.6.5 script/alphabetize
gman-4.6.4 script/alphabetize
gman-4.6.3 script/alphabetize
gman-4.6.2 script/alphabetize
gman-4.6.1 script/alphabetize
gman-4.6.0 script/alphabetize
gman-4.5.1 script/alphabetize
gman-4.5.0 script/alphabetize
gman-4.4.3 script/alphabetize
gman-4.4.2 script/alphabetize
gman-4.4.1 script/alphabetize
gman-4.4.0 script/alphabetize