Sfoglia il codice sorgente

Added Poll model

tags/last-sinatra-version
Adrian Short 14 anni fa
parent
commit
bc1087c24c
1 ha cambiato i file con 15 aggiunte e 1 eliminazioni
  1. +15
    -1
      models.rb

+ 15
- 1
models.rb Vedi File

@@ -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!

Caricamento…
Annulla
Salva