mirror of
https://github.com/Neetpone/foalfetch.git
synced 2025-02-09 02:16:43 +01:00
18 lines
383 B
Ruby
18 lines
383 B
Ruby
|
class RecountWordsJob < ApplicationJob
|
||
|
def perform(*)
|
||
|
Story.find_each do |story|
|
||
|
word_count = 0
|
||
|
story.chapters.each do |chapter|
|
||
|
count = chapter.body.split(' ').size
|
||
|
chapter.update_columns(
|
||
|
num_words: count
|
||
|
)
|
||
|
word_count += count
|
||
|
end
|
||
|
|
||
|
story.update_columns(
|
||
|
num_words: word_count
|
||
|
)
|
||
|
end
|
||
|
end
|
||
|
end
|