-
Notifications
You must be signed in to change notification settings - Fork 0
/
legislator_vote.rb
65 lines (53 loc) · 1.22 KB
/
legislator_vote.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# typed: strict
# == Schema Information
#
# Table name: legislator_votes
#
# id :integer not null, primary key
# legislator_id :integer not null
# bill_id :integer not null
# support :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class LegislatorVote < ApplicationRecord
extend T::Sig
belongs_to :legislator
belongs_to :bill
after_initialize :upcase_support
validates_inclusion_of :support, in: %w[FOR AGAINST ABSTAIN]
sig { returns(Bill) }
def bill
T.cast(super, Bill)
end
sig { returns(Legislator) }
def legislator
T.cast(super, Legislator)
end
sig { returns(T::Boolean) }
def for?
support == 'FOR'
end
sig { returns(T::Boolean) }
def against?
support == 'AGAINST'
end
sig { returns(T::Boolean) }
def abstain?
support.present? && !%w[FOR AGAINST].include?(support)
end
sig { returns(Jbuilder) }
def to_builder
Jbuilder.new do |lv|
lv.id id
lv.legislator_id legislator_id
lv.bill_id bill_id
lv.support support
end
end
private
sig { void }
def upcase_support
self.support = support.upcase.strip
end
end