Permalink
Browse files

hansard WIP

  • Loading branch information...
1 parent e68728d commit a24e728b098ab0c87c03e1f1cfbc71cd3798a787 @lachie committed Jun 22, 2009
View
@@ -0,0 +1,3 @@
+[submodule "vendor/plugins/acts_as_tree"]
+ path = vendor/plugins/acts_as_tree
+ url = git://github.com/rails/acts_as_tree.git
View
@@ -0,0 +1,39 @@
+class Hansard < ActiveRecord::Base
+ acts_as_tree
+ set_table_name 'hansard'
+
+ def self.import_xml!(xml)
+ hansard = Nokogiri::XML(open(xml))
+ first_heading = hansard.at('major-heading')
+ first_heading[:id][%r[/(\d{4}-\d{2}-\d{2})\.[^/]+]]
+ root = create!(:transcribed_at => Date.parse($1))
+
+ import!(hansard.search('//debates/*').to_a,[root])
+ end
+
+ def self.import!(list,stack)
+ xml = list.shift
+
+ kind = case xml.node_type
+ when 'speech'
+ :leaf
+ when 'major-heading','minor-heading'
+ :node
+ else
+ # skip
+ return
+ end
+
+ if kind == :node
+ stack.pop
+ end
+
+ next_item = stack.last.children.create!(parse_item(xml))
+
+ if kind == :node
+ stack << next_item
+ end
+
+ import!(list,stack)
+ end
+end
@@ -0,0 +1,21 @@
+class CreateHansards < ActiveRecord::Migration
+ def self.up
+ create_table :hansard do |t|
+ t.string :parlinfo_url
+
+ t.datetime :transcribed_at
+ t.string :section_identifier
+
+ t.belongs_to :parent
+ t.belongs_to :member
+
+ t.text :body
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :hansards
+ end
+end
View
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20090622062423) do
+ActiveRecord::Schema.define(:version => 20090622091112) do
create_table "electorates", :force => true do |t|
t.string "name"
@@ -19,6 +19,17 @@
t.datetime "updated_at"
end
+ create_table "hansard", :force => true do |t|
+ t.string "parlinfo_url"
+ t.datetime "transcribed_at"
+ t.string "section_identifier"
+ t.integer "parent_id"
+ t.integer "member_id"
+ t.text "body"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "houses", :force => true do |t|
t.string "name"
t.string "slug"

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,15 @@
+Feature: importing the hansard
+ As OpenAustralia
+ I want to import the hansard
+ So that we can see what's happening in parliament
+
+Scenario: Importing a day of hansard
+ Given a hansard file
+ And lots of speakers
+
+ When I import the hansard
+
+ Then I should see a root
+ And 54 major headings
+ And 32 minor headings
+ And 100 speeches
@@ -0,0 +1,27 @@
+Given /^a hansard file$/ do
+ @app.hansard.xml!
+end
+
+Given /^lots of speakers$/ do
+end
+
+When /^I import the hansard$/ do
+ @app.hansard.import_xml!
+end
+
+Then /^I should see a root$/ do
+ @app.hansard.fetch!.root?
+end
+
+Then /^(\d+) major headings$/ do |count|
+ @app.hansard.major_heading_count?(count.to_i)
+end
+
+Then /^(\d+) minor headings$/ do |count|
+ pending
+end
+
+Then /^(\d+) speeches$/ do |count|
+ pending
+end
+
@@ -0,0 +1,29 @@
+require File.dirname(__FILE__)+'/app_helper'
+
+module OA
+ class Hansard < Namespace
+ def xml!
+ @xml = fixture.path('reps_2009-06-04.xml')
+ self
+ end
+
+ def import_xml!
+ ::Hansard.import_xml!(@xml)
+ self
+ end
+
+ def fetch!
+ @target = ::Hansard.first
+ self
+ end
+
+ def root?
+ @target.root.should == @target
+ end
+
+ def major_heading_count?(count)
+ @target.children.count.should == count
+ end
+ end
+end
+
@@ -109,6 +109,7 @@ def do_after(&block)
namespace(:fixture,:Fixtures)
namespace(:member,:Member)
namespace(:house,:House)
+ namespace(:hansard,:Hansard)
end
end
@@ -12,6 +12,7 @@ def xmls_for!(member_name)
def import_xmls!
::House.import_xmls!(@xmls)
+ self
end
end
end
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
@@ -0,0 +1,12 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Hansard do
+ before(:each) do
+ @valid_attributes = {
+ }
+ end
+
+ it "should create a new instance given valid attributes" do
+ Hansard.create!(@valid_attributes)
+ end
+end
Submodule acts_as_tree added at 20988c

0 comments on commit a24e728

Please sign in to comment.