Skip to content

Commit

Permalink
add model helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
James McKinney committed Feb 24, 2013
1 parent 3d7d0e6 commit fef87da
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Expand Up @@ -30,7 +30,7 @@ def tab(body, url_options, html_options = {})
# @param [Person] person a person
# @return [String] the person's name prefixed by their role's title
def name_with_title(person)
[ @jurisdiction['chambers'][person['chamber']]['title'],
[ @jurisdiction.chamber_title(person['chamber']),
person.name,
].join(' ')
end
Expand Down
1 change: 1 addition & 0 deletions app/models/area.rb
Expand Up @@ -3,5 +3,6 @@ class Area
include Mongoid::Document
store_in collection: 'districts'

# @note Field in common with Popolo.
field :name, type: String
end
1 change: 1 addition & 0 deletions app/models/bill.rb
Expand Up @@ -2,6 +2,7 @@
class Bill
include Mongoid::Document

# For querying bills related to a committee.
index('actions.related_entities.id' => 1)

def questions # @todo
Expand Down
2 changes: 2 additions & 0 deletions app/models/committee.rb
Expand Up @@ -2,10 +2,12 @@
class Committee
include Mongoid::Document

# @note Field in common with Popolo.
def name
read_attribute(:subcommittee) || read_attribute(:committee)
end

# Returns the bills referred to this committee.
def bills
Bill.where('actions.related_entities.id' => id)
end
Expand Down
1 change: 1 addition & 0 deletions app/models/link.rb
@@ -1,4 +1,5 @@
# A URL for a document about a person.
# @note From Popolo.
class Link
include Mongoid::Document

Expand Down
16 changes: 16 additions & 0 deletions app/models/metadatum.rb
@@ -1,4 +1,20 @@
# Billy
class Metadatum
include Mongoid::Document

# Returns the brief name of the chamber.
#
# @param [String] chamber "lower" or "upper"
# @return [String] the brief name of the chamber
def chamber_name(chamber)
read_attribute(:chambers)[chamber]['name']
end

# Returns the title for members of the chamber.
#
# @param [String] chamber "lower" or "upper"
# @return [String] the title for members of the chamber
def chamber_title(chamber)
read_attribute(:chambers)[chamber]['title']
end
end
3 changes: 2 additions & 1 deletion app/models/person.rb
Expand Up @@ -3,9 +3,10 @@ class Person
include Mongoid::Document
store_in collection: 'legislators'

# For sorting on people#index.
index(chamber: 1, last_name: 1)

# Non-Billy
# Stores Popolo fields that are not available in Billy.
has_one :person_detail, autobuild: true

field :full_name, type: String, as: :name
Expand Down
1 change: 1 addition & 0 deletions app/models/person_detail.rb
@@ -1,4 +1,5 @@
# Exists only because we blow away the `people` collection regularly.
# @note Based on Popolo.
class PersonDetail
include Mongoid::Document

Expand Down
2 changes: 2 additions & 0 deletions app/views/bills/show.html.erb
@@ -1,5 +1,7 @@
<%= render 'shared/navigation' %>
<%= @jurisdiction.chamber_name(@bill['chamber']) %>

<section class="bills">
<header>
<div class="bill_info">
Expand Down
2 changes: 1 addition & 1 deletion app/views/committees/index.html.erb
Expand Up @@ -4,7 +4,7 @@
<ol>
<% @committees.asc(:committee, :subcommittee).each do |committee| %>
<li>
<%= committee['chamber'] %>
<%= @jurisdiction.chamber_name(committee['chamber']) %>
<% if committee['subcommittee'] %>
<%= link_to committee['committee'], committee_path(@jurisdiction.id, committee['parent_id']) %>:
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/committees/show.html.erb
@@ -1,7 +1,7 @@
<%= render 'shared/navigation' %>

<section>
<%= @committee['chamber'] %>
<%= @jurisdiction.chamber_name(@committee['chamber']) %>
<% if @committee['subcommittee'] %>
<%= link_to @committee['committee'], committee_path(@jurisdiction.id, @committee['parent_id']) %>:
<% end %>
Expand Down
7 changes: 0 additions & 7 deletions db/seeds.rb

This file was deleted.

1 change: 1 addition & 0 deletions doc/README.md
@@ -0,0 +1 @@
`indexes.txt` is output by `mongorestore` when loading the [OpenStates MongoDB dump](http://static.openstates.org.s3.amazonaws.com/mongo/latest-mongo-dump.tar.gz).

0 comments on commit fef87da

Please sign in to comment.