Module: XMP2Assert::Classifier
- Defined in:
- lib/xmp2assert/classifier.rb
Overview
Usually, you want to check LOTS of files that may or may not contain xmp comments at once, maybe from inside of a CI process. That's OK but we want to speed things up, so here we filter out files that are not necessary to convert.
Typical usage:
Pathname.glob('**/*.rb').select do |f|
XMP2Assert::Classifier.classify(f)
end
Class Method Summary collapse
-
.classify(obj, file = nil, line = nil) ⇒ <Symbol>
Either empty, :=>, :>>, or both.
Class Method Details
.classify(obj, file = nil, line = nil) ⇒ <Symbol>
Note:
syntax error results in empty return value.
Returns either empty, :=>, :>>, or both.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xmp2assert/classifier.rb', line 46 def self.classify obj, file = nil, line = nil parser = XMP2Assert::Parser.new obj, file, line rescue SyntaxError return [] else return parser \ .tokens \ .map(&:to_sym) \ .sort \ .uniq \ .map {|i| case i when :'=>', :'>>' then i else nil end } \ .compact end |