Class: Spellr::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/spellr/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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_fileObject

Returns the value of attribute config_file.



12
13
14
# File 'lib/spellr/config.rb', line 12

def config_file
  @config_file
end

#quietObject Also known as: quiet?

Returns the value of attribute quiet.



13
14
15
# File 'lib/spellr/config.rb', line 13

def quiet
  @quiet
end

#reporterObject



85
86
87
# File 'lib/spellr/config.rb', line 85

def reporter
  @reporter ||= default_reporter
end

Instance Method Details

#colorObject



58
59
60
# File 'lib/spellr/config.rb', line 58

def color
  @config[:color]
end

#errorsObject



34
35
36
# File 'lib/spellr/config.rb', line 34

def errors
  @errors ||= []
end

#excludesObject



54
55
56
# File 'lib/spellr/config.rb', line 54

def excludes
  @excludes ||= @config[:excludes] || []
end

#includesObject



50
51
52
# File 'lib/spellr/config.rb', line 50

def includes
  @includes ||= @config[:includes] || []
end

#key_heuristic_weightObject



42
43
44
# File 'lib/spellr/config.rb', line 42

def key_heuristic_weight
  @key_heuristic_weight ||= @config[:key_heuristic_weight]
end

#key_minimum_lengthObject



46
47
48
# File 'lib/spellr/config.rb', line 46

def key_minimum_length
  @key_minimum_length ||= @config[:key_minimum_length]
end

#languagesObject



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


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

#pwdObject



68
69
70
# File 'lib/spellr/config.rb', line 68

def pwd
  @pwd ||= Pathname.pwd
end

#valid?Boolean

Returns:

  • (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_lengthObject



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