Class: Merimee::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



21
22
23
24
25
26
27
28
# File 'lib/merimee/config.rb', line 21

def initialize
  @dictionary = []
  @severity = {}
  ignore(Merimee::DEFAULT_IGNORE_TYPES)

  @api_key = Config.generate_api_key
  @language = Merimee::DEFAULT_LANGUAGE
end

Instance Attribute Details

#api_keyObject

This is required by the service for caching purposes, but no registration is needed (api_key should just be unique for your app, only one request can happen per key at any moment). There shouldn’t be any need for this, but still



15
16
17
# File 'lib/merimee/config.rb', line 15

def api_key
  @api_key
end

#dictionaryObject

Returns the value of attribute dictionary.



8
9
10
# File 'lib/merimee/config.rb', line 8

def dictionary
  @dictionary
end

#languageObject

The language to use for this check This is used to select the proper AtD server, unless overriden with the :language option



19
20
21
# File 'lib/merimee/config.rb', line 19

def language
  @language
end

#severityObject (readonly)

Returns the value of attribute severity.



9
10
11
# File 'lib/merimee/config.rb', line 9

def severity
  @severity
end

Instance Method Details

#cloneObject



60
61
62
63
64
65
66
67
# File 'lib/merimee/config.rb', line 60

def clone
  ret = Config.new
  ret.dictionary = @dictionary.dup
  ret.severity.update(@severity)
  ret.api_key = api_key
  ret.language = language
  ret
end

#dict_add(word) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/merimee/config.rb', line 48

def dict_add(word)
  if word.kind_of?(String)
    @dictionary << word
  elsif word.kind_of?(Enumerable)
    @dictionary.concat word
  end
end

#dict_add_file(file) ⇒ Object



56
57
58
# File 'lib/merimee/config.rb', line 56

def dict_add_file(file)
  File.open(file) {|f| dict_add(f.readlines.map(&:strip)) }
end

#error(types) ⇒ Object



36
37
38
# File 'lib/merimee/config.rb', line 36

def error(types)
  set_type_severity(types, :error)
end

#ignore(types) ⇒ Object



30
31
32
# File 'lib/merimee/config.rb', line 30

def ignore(types)
  set_type_severity(types, :ignore)
end

#set_type_severity(types, level) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/merimee/config.rb', line 39

def set_type_severity(types, level)
  unless types.kind_of?(Enumerable)
    types = [types]
  end
  types.each do |t|
    @severity[t.to_s.downcase] = level
  end
end

#warn(types) ⇒ Object



33
34
35
# File 'lib/merimee/config.rb', line 33

def warn(types)
  set_type_severity(types, :warn)
end