Class: AnyStyle::CLI::Commands::Find
- Defined in:
- lib/anystyle/cli/commands/find.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#each_format, #extsub, #find, #format, #initialize, #overwrite?, #parse, #say, #set_output_folder, #stdout?, #transpose, #verbose?, #walk, #write
Constructor Details
This class inherits a constructor from AnyStyle::CLI::Commands::Base
Instance Method Details
#run(args, params) ⇒ Object
5 6 7 8 9 10 11 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 38 39 40 |
# File 'lib/anystyle/cli/commands/find.rb', line 5 def run(args, params) set_output_folder args[1] walk args[0] do |path, base_path| say "Analyzing #{path.relative_path_from(base_path)} ..." doc = find(path.to_s.untaint, layout: params[:layout]) ref = doc[0].references if ref.length == 0 say "no references found.\n" else say "#{ref.length} references found.\n" dst = nil each_format do |fmt| case fmt when 'ttx' say "Formatting document as #{fmt} ...\n" res = doc.to_txt tagged: true when 'txt' say "Formatting document as #{fmt} ...\n" res = doc.to_txt tagged: false when 'ref' say "Formatting references as #{fmt} ...\n" res = ref.join("\n") else say "Formatting references as #{fmt} ...\n" dst ||= parse(ref.join("\n")) res = format(dst, fmt) end out = extsub(path, ".#{fmt}") say "Writing #{out.relative_path_from(base_path)} ...\n" write res, out, base_path end end end end |