Class: DK::Autofixer::GenerateTagsYml
- Inherits:
-
Object
- Object
- DK::Autofixer::GenerateTagsYml
- Defined in:
- lib/autofixer/commands/generate_tags_yml.rb
Overview
Generate tags.yml using DK
Instance Method Summary collapse
- #confile(fname) ⇒ Object
- #home_file(file) ⇒ Object
-
#initialize(opts) ⇒ GenerateTagsYml
constructor
A new instance of GenerateTagsYml.
- #opt_val(opt, default = nil) ⇒ Object
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) = {} [:limit] = opt_val('-l') || 1000 [:blog] = opt_val('-b') [:config] = opt_val('--config') [:source] = opt_val('--source') || DK::PUBLISH # Get Posts dk = DK::Client.new() posts = dk.get_posts.map { |post| DK::Post.new post } posts = posts.select { |post| !post..empty? } # Collect Tags @tags = [] posts.each { |post| @tags += post. } @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 |