Class: Spellr::Config
- Inherits:
-
Object
- Object
- Spellr::Config
- Defined in:
- lib/spellr/config.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#quiet ⇒ Object
(also: #quiet?)
Returns the value of attribute quiet.
- #reporter ⇒ Object
Instance Method Summary collapse
- #color ⇒ Object
- #errors ⇒ Object
- #excludes ⇒ Object
- #includes ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #key_heuristic_weight ⇒ Object
- #key_minimum_length ⇒ Object
- #languages ⇒ Object
- #languages_for(file) ⇒ Object
- #print_errors ⇒ Object
- #pwd ⇒ Object
- #valid? ⇒ Boolean
- #word_minimum_length ⇒ Object
- #wordlists_for(file) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
16 17 18 |
# File 'lib/spellr/config.rb', line 16 def initialize @config = ConfigLoader.new end |
Instance Attribute Details
#config_file ⇒ Object
Returns the value of attribute config_file.
12 13 14 |
# File 'lib/spellr/config.rb', line 12 def config_file @config_file end |
#quiet ⇒ Object Also known as: quiet?
Returns the value of attribute quiet.
13 14 15 |
# File 'lib/spellr/config.rb', line 13 def quiet @quiet end |
#reporter ⇒ Object
85 86 87 |
# File 'lib/spellr/config.rb', line 85 def reporter @reporter ||= default_reporter end |
Instance Method Details
#color ⇒ Object
58 59 60 |
# File 'lib/spellr/config.rb', line 58 def color @config[:color] end |
#errors ⇒ Object
34 35 36 |
# File 'lib/spellr/config.rb', line 34 def errors @errors ||= [] end |
#excludes ⇒ Object
54 55 56 |
# File 'lib/spellr/config.rb', line 54 def excludes @excludes ||= @config[:excludes] || [] end |
#includes ⇒ Object
50 51 52 |
# File 'lib/spellr/config.rb', line 50 def includes @includes ||= @config[:includes] || [] end |
#key_heuristic_weight ⇒ Object
42 43 44 |
# File 'lib/spellr/config.rb', line 42 def key_heuristic_weight @key_heuristic_weight ||= @config[:key_heuristic_weight] end |
#key_minimum_length ⇒ Object
46 47 48 |
# File 'lib/spellr/config.rb', line 46 def key_minimum_length @key_minimum_length ||= @config[:key_minimum_length] end |
#languages ⇒ Object
62 63 64 65 66 |
# File 'lib/spellr/config.rb', line 62 def languages @languages ||= @config[:languages].map do |key, args| Spellr::Language.new(key, **args) end end |
#languages_for(file) ⇒ Object
72 73 74 |
# File 'lib/spellr/config.rb', line 72 def languages_for(file) languages.select { |l| l.matches?(file) } end |
#print_errors ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/spellr/config.rb', line 26 def print_errors if $stderr.tty? errors.each { |e| warn "\e[31m#{e}\e[0m" } else errors.each { |e| warn e } end end |
#pwd ⇒ Object
68 69 70 |
# File 'lib/spellr/config.rb', line 68 def pwd @pwd ||= Pathname.pwd end |
#valid? ⇒ Boolean
20 21 22 23 24 |
# File 'lib/spellr/config.rb', line 20 def valid? only_has_one_key_per_language keys_are_single_characters errors.empty? end |
#word_minimum_length ⇒ Object
38 39 40 |
# File 'lib/spellr/config.rb', line 38 def word_minimum_length @word_minimum_length ||= @config[:word_minimum_length] end |
#wordlists_for(file) ⇒ Object
76 77 78 |
# File 'lib/spellr/config.rb', line 76 def wordlists_for(file) languages_for(file).flat_map(&:wordlists) end |