Class: AnyStyle::CLI::Commands::Check

Inherits:
Base
  • Object
show all
Defined in:
lib/anystyle/cli/commands/check.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #output_folder

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

#check(path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/anystyle/cli/commands/check.rb', line 14

def check(path)
  case path.extname
  when '.ttx'
    AnyStyle.finder.check path.to_s.untaint
  when '.xml'
    AnyStyle.parser.check path.to_s.untaint
  else
    raise ArgumentError, "cannot check untagged input: #{path}"
  end
end

#report(stats, time) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/anystyle/cli/commands/check.rb', line 25

def report(stats, time)
  if stats[:token][:errors] == 0
    puts '   ✓                               %2ds' % time
  else
    puts '%4d seq %6.2f%% %6d tok %5.2f%% %2ds' % [
      stats[:sequence][:errors],
      stats[:sequence][:rate],
      stats[:token][:errors],
      stats[:token][:rate],
      time
    ]
  end
end

#run(args, params) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/anystyle/cli/commands/check.rb', line 5

def run(args, params)
  walk args[0] do |path|
    print 'Checking %.25s' % "#{path.basename}....................."
    start = Time.now
    stats = check path
    report stats, Time.now - start
  end
end