Sha256: 4fe07a032b1c3ef9b6277229b248543e7691be55aaf1ffb4e0d64df0fab13ef6
Contents?: true
Size: 1.59 KB
Versions: 3
Compression:
Stored size: 1.59 KB
Contents
require "yaml" require "active_support" require "active_support/core_ext" require "active_support/inflector" # numeric test class String def number? true if Float(self) rescue false end end module Hasmenu class SpellChecker include Printer def initialize(options) @dictd = options[:dicts] || File.join(Dir.pwd, ".meta", "dicts") @xcept = options[:except] @dicts = [] end def load_dicts yamls = Dir.glob("#{@dictd}/*.yml") yamls.each do |yaml| @dicts << YAML.load_file(yaml) end end def values_of(h) h.values.flatten.map do |e| if e.is_a?(Hash) values_of(e) else e.to_s.parameterize.split(/[^\w]/) end end end def spell_check(path) xcept = @xcept || File.basename(File.dirname(path)) xyaml = File.join(@dictd, "excepts", xcept + ".yml") if File.file? xyaml except = YAML.load_file(xyaml) @dicts << except end data = YAML.load_file(path) diff = values_of(data).flatten.sort.uniq - @dicts.flatten diff = diff.compact.delete_if(&:number?) print_header path puts diff if diff.present? end def spell_check_all(path) Dir.glob(path + "/**/*.yml") do |file| spell_check file end end def check(path) unless File.exist? path print_invalid_path return end load_dicts if File.file? path spell_check path elsif File.directory? path spell_check_all path else print_invalid_path end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hasmenu-0.1.6 | lib/hasmenu/spellchecker.rb |
hasmenu-0.1.5 | lib/hasmenu/spellchecker.rb |
hasmenu-0.1.4 | lib/hasmenu/spellchecker.rb |