Module: Profane

Defined in:
lib/profane.rb,
lib/profane/filter.rb,
lib/profane/version.rb

Defined Under Namespace

Classes: Filter

Constant Summary collapse

DICTIONARY_PATH =
File.expand_path('../../config/dictionary.yml', __FILE__)
VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.characterObject



32
33
34
# File 'lib/profane.rb', line 32

def self.character
  config[:filter_character] || '*'
end

.configObject



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

def self.config
  @config ||= set_default_config
end

.configure(options) ⇒ Object



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

def self.configure(options)
  config.merge!(options)
end

.dictionaryObject



20
21
22
# File 'lib/profane.rb', line 20

def self.dictionary
  stringify_keys(load_dictionary)
end

.load_custom_yaml_dictionaryObject



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

def self.load_custom_yaml_dictionary
  path = config[:dictionary_file]

  if path && File.exist?(path)
    YAML.load(File.read(config[:dictionary_file]))
  else
    {}
  end
end

.load_dictionaryObject



36
37
38
39
40
41
42
43
44
# File 'lib/profane.rb', line 36

def self.load_dictionary
  yaml_dictionary = load_yaml_dictionary

  if config[:use_internal_dictionary]
    yaml_dictionary.merge (config[:dictionary] || {})
  else
    config[:dictionary]
  end
end

.load_internal_yaml_dictionaryObject



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

def self.load_internal_yaml_dictionary
  internal_dictionary = YAML.load(File.read(DICTIONARY_PATH))
end

.load_yaml_dictionaryObject



46
47
48
49
50
51
52
53
54
# File 'lib/profane.rb', line 46

def self.load_yaml_dictionary
  custom_dictionary = load_custom_yaml_dictionary

  if config[:use_internal_dictionary]
    load_internal_yaml_dictionary.merge custom_dictionary
  else
    custom_dictionary
  end
end

.set_default_configObject



16
17
18
# File 'lib/profane.rb', line 16

def self.set_default_config
  @config = { use_internal_dictionary: true }
end

.stringify_keys(hash) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/profane.rb', line 24

def self.stringify_keys(hash)
  hash.keys.each do |key|
    hash[key.to_s] = hash.delete(key)
  end

  hash
end