public
Description:
Homepage: http://www.michaelbarton.me.uk
Clone URL: git://github.com/michaelbarton/cost_in_evolution.git
cost_in_evolution / model / stage.rb
100644 34 lines (26 sloc) 0.708 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Stage < DataMapper::Base
  include Comparable
 
  property :number, :integer
  property :title, :text
  property :description, :text
 
  belongs_to :project
 
  def <=> other
     self.number <=> other.number
  end
 
  def html_description
    BlueCloth.new(self.description).to_html
  end
 
  def html_summary
    self.html_description.split(/\n/).first.strip
  end
 
  def self.create_from_markdown_erb(number,file)
    self.all(:number => number).each {|r| r.destroy!}
    File.open(file) do |f|
      return self.create({
        :number => number,
        :title => f.readline.gsub(/#+\s/,'').strip,
        :description => ERB.new(f.read.strip).result
      })
    end
  end
 
end