Advertisement
Guest User

Untitled

a guest
May 26th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.88 KB | None | 0 0
  1.   def self.find_existing(domain, url_id)
  2.     Article.where(web_domain:domain,url_id:url_id).first
  3.   end
  4.  
  5.   def content_lines
  6.     if @content_lines.nil?
  7.       regular_exp = /(?:    # Either match...
  8.                       「.*」  # a quoted sentence
  9.                     |         # or
  10.                       [^「」『』。?!]*   # anything except quotes or dots.
  11.                     )+        # Repeat as needed
  12.                     [。?!]\s*     # Then match a dot and optionally some whitespace.
  13.                     /x
  14.       @content_lines = content.scan(regular_exp)
  15.       @content_lines.each do |cl| cl.gsub!(/[[:space:]]/, ' ') end
  16.       @content_lines.each(&:strip!)
  17.     end
  18.     @content_lines
  19.   end
  20.  
  21.   before_create :build_lines
  22.   def build_lines
  23.     content_lines.each_with_index do |line, index|
  24.       lines.build(text:line, line_number:index+1)
  25.     end
  26.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement