Class: DK::Autofixer::GenerateTagsYml

Inherits:
Object
  • Object
show all
Defined in:
lib/autofixer/commands/generate_tags_yml.rb

Overview

Generate tags.yml using DK

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ GenerateTagsYml

Returns a new instance of GenerateTagsYml.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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

Instance Method Details

#confile(fname) ⇒ Object



47
48
49
# File 'lib/autofixer/commands/generate_tags_yml.rb', line 47

def confile(fname)
  home_file('/config_md/taf/') + fname
end

#home_file(file) ⇒ Object



43
44
45
# 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) ⇒ Object



39
40
41
# 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