Class: DcBookChapter

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/dc_book_chapter.rb

Overview

Schema information

Collection name: dc_book_chapter : Chapter

_id                  BSON::ObjectId       _id
created_at           Time                 created_at
updated_at           Time                 updated_at
title                String               Chapter title
chapter              String               Chapter number. Can be nested 01.10.08.1
link                 String               link
author               String               Author's name
can_comment          Mongoid::Boolean     Comments are allowed
active               Mongoid::Boolean     active
created_by           BSON::ObjectId       created_by
updated_by           BSON::ObjectId       updated_by
dc_book_id           Object               Book title
dc_book_texts        Embedded:DcBookText  dc_book_texts
dc_replies           Embedded:DcReply     dc_replies

Instance Method Summary collapse

Instance Method Details

Clears subject link of chars that shouldn’t be there and also take care of its size



72
73
74
75
76
77
78
79
# File 'app/models/dc_book_chapter.rb', line 72

def clear_link(link)
  link.gsub!(/\.|\?|\!\&|»|«|\,|\"|\'|\:/,'')
  link.gsub!('<br>','')
  link.gsub!(' ','-')
  link.gsub!('---','-')
  link.gsub!('--','-')
  link
end

#do_before_saveObject



82
83
84
85
86
# File 'app/models/dc_book_chapter.rb', line 82

def do_before_save
  if self.link.empty?
    self.link = clear_link("#{self.chapter}-#{self.title.downcase.strip}")
  end
end