Class: Hasmenu::SpellChecker
- Inherits:
-
Object
- Object
- Hasmenu::SpellChecker
show all
- Includes:
- Printer
- Defined in:
- lib/hasmenu/spellchecker.rb
Instance Method Summary
collapse
Methods included from Printer
#print_build_for, #print_build_start, #print_format_for, #print_format_start, #print_header, #print_invalid_build, #print_invalid_format, #print_invalid_path, #print_invalid_report, #print_invalid_sequence, #print_invalid_version, #print_report, #print_warn_repeats
Constructor Details
Returns a new instance of SpellChecker.
17
18
19
20
21
|
# File 'lib/hasmenu/spellchecker.rb', line 17
def initialize(options)
@dictd = options[:dicts] || File.join(Dir.pwd, "dict")
@xcept = options[:except]
@dicts = []
end
|
Instance Method Details
#check(path) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/hasmenu/spellchecker.rb', line 64
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
|
#load_dicts ⇒ Object
23
24
25
26
27
28
|
# File 'lib/hasmenu/spellchecker.rb', line 23
def load_dicts
yamls = Dir.glob("#{@dictd}/*.yml")
yamls.each do |yaml|
@dicts << YAML.load_file(yaml)
end
end
|
#spell_check(path) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/hasmenu/spellchecker.rb', line 40
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?)
path
puts diff if diff.present?
end
|
#spell_check_all(path) ⇒ Object
58
59
60
61
62
|
# File 'lib/hasmenu/spellchecker.rb', line 58
def spell_check_all(path)
Dir.glob(File.join(path, "**", "*.yml")) do |file|
spell_check file
end
end
|
#values_of(h) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/hasmenu/spellchecker.rb', line 30
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
|