diff --git a/app.rb b/app.rb index 49eca12..9bc1724 100644 --- a/app.rb +++ b/app.rb @@ -10,6 +10,10 @@ helpers do def commify(amount) amount.to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse end + + def yesno(boolean) + boolean == true ? 'Yes' : 'No' + end end get '/' do @@ -143,6 +147,11 @@ get '/about' do haml :about end +get '/scoreboard' do + @councils = Council.all( :order => ['name'] ) + haml :scoreboard +end + not_found do haml :not_found end \ No newline at end of file diff --git a/lib/models.rb b/lib/models.rb index 6a5f2d9..4c09d89 100644 --- a/lib/models.rb +++ b/lib/models.rb @@ -88,5 +88,28 @@ class Supplier end end +class Council + include DataMapper::Resource + + property :id, Serial + property :created_at, DateTime + property :updated_at, DateTime + property :name, String, :length => 255, :required => true + property :slug, String, :length => 255 + property :url, String, :length => 255 + property :data_url, String, :length => 512 + property :open_licence, Boolean, :default => false + property :machine_readable, Boolean, :default => false + property :grade, String, :length => 1 + property :start_d, Date + property :end_d, Date + + before :save, :slugify + + def slugify + @slug = @name.gsub(/[^\w\s-]/, '').gsub(/\s+/, '-').downcase + end +end + DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db.sqlite3") DataMapper.auto_upgrade! diff --git a/views/scoreboard.haml b/views/scoreboard.haml new file mode 100644 index 0000000..395e1e6 --- /dev/null +++ b/views/scoreboard.haml @@ -0,0 +1,26 @@ +.grid_12 + %h2= @page_title = "Council Spending Data Scoreboard" + + %table + %tr + %th Council + %th Data URL + %th Open licence? + %th Machine readable? + %th Start + %th End + %th Updated + + - for council in @councils + %tr + %td + %a{ :href => council.url } + = council.name + %td + %a{ :href => council.data_url } + data + %td= yesno(council.open_licence) + %td= yesno(council.machine_readable) + %td= council.start_d.strftime("%b %Y") + %td= council.end_d.strftime("%b %Y") + %td= council.updated_at.strftime("%d %b %Y") \ No newline at end of file