class Line < ActiveRecord::Base
  belongs_to :person
  belongs_to :quote
  
  validates :person, :body, presence: true
  
  PATTERNS = [
    [ /<\s*([^>]+)\s*>\s*(.*)$/, false ],
    [ /\*\s+([^\s]+)\s*(.*)$/,   true ],
    [ /([^:]+):\s*(.*)$/,        false ],
  ]
  
  def self.from_raw_line(raw_line)
    PATTERNS.each do |pattern|
      regex, action = pattern
      if raw_line =~ regex
        person = Person.find_or_create_by_name($1)
        return Line.new(person: person, body: $2, action: action)
      end
    end
    raise Exception.new("Failed to parse #{raw_line}")
  end
end

class Line < ActiveRecord::Base
  belongs_to :person
  belongs_to :quote
  
  validates :person, :body, presence: true
  
  PATTERNS = [
    [ /<\s*([^>]+)\s*>\s*(.*)$/, false ],
    [ /\*\s+([^\s]+)\s*(.*)$/,   true ],
    [ /([^:]+):\s*(.*)$/,        false ],
    [ /^([^\s]+)\s*(.*)$/,       true ],
  ]
  
  def self.from_raw_line(raw_line)
    PATTERNS.each do |pattern|
      regex, action = pattern
      if raw_line =~ regex
        person = Person.find_or_create_by_name($1)
        return Line.new(person: person, body: $2, action: action)
      end
    end
    raise Exception.new("Failed to parse #{raw_line}")
  end
end

Support action format from Skyshaper Wiki quotes
Support action format from Skyshaper Wiki quotes
