瀏覽代碼

Added Poll model

tags/last-sinatra-version
Adrian Short 14 年之前
父節點
當前提交
bc1087c24c
共有 1 個檔案被更改,包括 15 行新增1 行删除
  1. +15
    -1
      models.rb

+ 15
- 1
models.rb 查看文件

@@ -1,6 +1,20 @@
require 'data_mapper'
require 'pat'

class Poll
include DataMapper::Resource

property :district_id, Integer, :key => true
property :election_id, Integer, :key => true
property :electorate, Integer # The number of people eligible to vote in this district in this election
property :ballot_papers_issued, Integer # The number of ballot papers issued (includes spoiled ballots)
property :seats, Integer, :required => true # The number of seats to be elected in this district in this election
def turnout_percent
@ballot_papers_issued.to_f / @electorate.to_f * 100.0
end
end

class Postcode
include DataMapper::Resource

@@ -209,4 +223,4 @@ class Constituency
end

DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db/suttonelections.db")
DataMapper.auto_upgrade!
DataMapper.auto_upgrade!

Loading…
取消
儲存