class DK::Autofixer::GenerateTagsYml

Generate tags.yml using DK

Public Class Methods

new(opts) click to toggle source
# File lib/autofixer/commands/generate_tags_yml.rb, line 12
def initialize(opts)
  options = {}
  options[:limit]   = opt_val('-l') || 1000
  options[:blog]    = opt_val('-b')
  options[:config]  = opt_val('--config')
  options[:source]  = opt_val('--source') || DK::PUBLISH
  # Get Posts
  dk    = DK::Client.new(options)
  posts = dk.get_posts.map { |post| DK::Post.new post  }
  posts = posts.select { |post| !post.tags.empty? }
  # Collect Tags
  @tags = []
  posts.each { |post| @tags += post.tags }
  @tstore  = YAML::Store.new("#{confile('tags.yml')}")
  # Preserve existing
  existing = restore(@tstore, :good)
  # puts "Found #{existing.size} tags." if existing
  @tags += existing if existing
  @tags  = @tags.map(&:downcase)
  @tags.uniq!
  @tags.sort!
  # Save
  # puts "Saving #{@tags.size} tags"
  store(@tstore, :good, @tags)

end

Public Instance Methods

confile(fname) click to toggle source
# File lib/autofixer/commands/generate_tags_yml.rb, line 47
def confile(fname)
  home_file('/config_md/taf/') + fname
end
home_file(file) click to toggle source
# File lib/autofixer/commands/generate_tags_yml.rb, line 43
def home_file(file)
  DK::Config.home_path_file(file)
end
opt_val(opt, default=nil) click to toggle source
# File lib/autofixer/commands/generate_tags_yml.rb, line 39
def opt_val(opt, default=nil)
  ARGV[ARGV.find_index(opt) + 1] rescue default
end