Class: WatchedWord

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/watched_word.rb

Constant Summary collapse

MAX_WORDS_PER_ACTION =
2000

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.actionsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/watched_word.rb', line 42

def self.actions
  @actions ||=
    Enum.new(
      block: 1,
      censor: 2,
      require_approval: 3,
      flag: 4,
      link: 8,
      replace: 5,
      tag: 6,
      silence: 7,
    )
end

.create_or_update_word(params) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/watched_word.rb', line 66

def self.create_or_update_word(params)
  word = normalize_word(params[:word])
  word = self.for(word: word).first_or_initialize(word: word)
  word.replacement = params[:replacement] if params[:replacement]
  word.action_key = params[:action_key] if params[:action_key]
  word.action = params[:action] if params[:action]
  word.case_sensitive = params[:case_sensitive] if !params[:case_sensitive].nil?
  word.html = params[:html] if params[:html]
  word.watched_word_group_id = params[:watched_word_group_id]
  word.save
  word
end

.has_replacement?(action) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/watched_word.rb', line 79

def self.has_replacement?(action)
  action == :replace || action == :tag || action == :link
end

Instance Method Details

#action_key=(arg) ⇒ Object



83
84
85
# File 'app/models/watched_word.rb', line 83

def action_key=(arg)
  self.action = WatchedWord.actions[arg.to_sym]
end

#action_log_detailsObject



87
88
89
# File 'app/models/watched_word.rb', line 87

def action_log_details
  replacement.present? ? "#{word} → #{replacement}" : word
end