Skip to content

Commit

Permalink
- Explicitly convert to date when formatting dates in date helper
Browse files Browse the repository at this point in the history
- Rework EDM amendments method so that it will cope with partial data, which was causing some data to be missing
  • Loading branch information
j-corry committed Aug 28, 2024
1 parent 198965c commit c7c8ca8
Show file tree
Hide file tree
Showing 8 changed files with 879 additions and 977 deletions.
2 changes: 1 addition & 1 deletion app/helpers/date_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ def format_date(data)

return if data[:value].blank?

data[:value].strftime(ApplicationHelper::DATE_DISPLAY_FORMAT)
data[:value].to_date.strftime(ApplicationHelper::DATE_DISPLAY_FORMAT)
end
end
1 change: 0 additions & 1 deletion app/models/content_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def associated_objects
end

def amendments
# TODO: temporary superclass method for non-EDM objects to be able to use a standard view for all result types
nil
end

Expand Down
49 changes: 20 additions & 29 deletions app/models/edm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,29 @@ def amendments
# Title is the title of the motion itself, with 'Amendment N' on the front
# Reference is taken from identifier_t, after removing the first item

return if content_object_data['amendmentText_t'].blank?
return if content_object_data['amendment_numberOfSignatures_s'].blank?
return if content_object_data['amendment_primarySponsorPrinted_t'].blank?
return if content_object_data['amendment_primarySponsorParty_ses'].blank?
return if content_object_data['identifier_t'].blank?
return if content_object_data['amendment_dateTabled_dt'].blank?

original_hash = {
text: content_object_data['amendmentText_t'],
number_of_signatures: content_object_data['amendment_numberOfSignatures_s'],
primary_sponsor: content_object_data['amendment_primarySponsorPrinted_t'],
primary_sponsor_party: content_object_data['amendment_primarySponsorParty_ses'],
reference: content_object_data['identifier_t'].drop(1),
date_tabled: content_object_data['amendment_dateTabled_dt'],
text: content_object_data['amendmentText_t'].blank? ? {} : { value: content_object_data['amendmentText_t'], field_name: 'amendmentText_t' },
number_of_signatures: content_object_data['amendment_numberOfSignatures_s'].blank? ? {} : { value: content_object_data['amendment_numberOfSignatures_s'], field_name: 'amendment_numberOfSignatures_s' },
primary_sponsor: content_object_data['amendment_primarySponsor_ses'].blank? ? {} : { value: content_object_data['amendment_primarySponsor_ses'], field_name: 'amendment_primarySponsor_ses' },
primary_sponsor_text: content_object_data['amendment_primarySponsorPrinted_t'].blank? ? {} : { value: content_object_data['amendment_primarySponsorPrinted_t'], field_name: 'amendment_primarySponsorPrinted_t' },
primary_sponsor_party: content_object_data['amendment_primarySponsorParty_ses'].blank? ? {} : { value: content_object_data['amendment_primarySponsorParty_ses'], field_name: 'amendment_primarySponsorParty_ses' },
reference: content_object_data['identifier_t']&.drop(1).blank? ? {} : { value: content_object_data['identifier_t']&.drop(1), field_name: 'identifier_t' },
date_tabled: content_object_data['amendment_dateTabled_dt'].blank? ? {} : { value: content_object_data['amendment_dateTabled_dt'], field_name: 'amendment_dateTabled_dt' }
}

result_hashes = original_hash[:text].zip(
original_hash[:number_of_signatures],
original_hash[:primary_sponsor],
original_hash[:primary_sponsor_party],
original_hash[:reference],
original_hash[:date_tabled],
).map.with_index do |values, index|
{
index: index,
text: { value: values[0], field_name: 'amendmentText_t' },
number_of_signatures: { value: values[1], field_name: 'amendment_numberOfSignatures_s' },
primary_sponsor: { value: values[2], field_name: 'amendment_primarySponsorPrinted_t' },
primary_sponsor_party: { value: values[3], field_name: 'amendment_primarySponsorParty_ses' },
reference: { value: values[4], field_name: 'identifier_t' },
date_tabled: { value: values[5]&.to_date, field_name: 'amendment_dateTabled_dt' },
}
return [] if original_hash.values.pluck(:value).compact.blank?

number_of_amendments = original_hash.values.pluck(:value).compact.map(&:size).max
keys = original_hash.keys
result_hashes = []

number_of_amendments.times do |iteration|
ret = {}
keys.each do |key|
ret[key] = { value: original_hash.dig(key, :value).blank? ? nil : original_hash.dig(key, :value)[iteration], field_name: original_hash.dig(key, :field_name) }
end
ret[:index] = iteration
result_hashes << ret
end

result_hashes
Expand Down
1 change: 1 addition & 0 deletions app/views/search/results/item_details/_content.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="item-details">
<span>
<%= raw content[:value].truncate_words(50) %>
<!-- Nokogiri::HTML::DocumentFragment.parse(html).to_html-->
</span>
</div>
<% end %>
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"line": 83.05
"line": 83.14
}
}
122 changes: 56 additions & 66 deletions coverage/.resultset.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,19 @@
null,
null,
null,
1796,
1799,
null,
1795,
1795,
1798,
1798,
null,
1795,
1798,
null,
null,
1,
2002,
2005,
204,
null,
1798,
1801,
null,
null,
null,
Expand Down Expand Up @@ -259,7 +259,7 @@
null,
null,
1,
2422,
2425,
null,
null,
1,
Expand All @@ -268,28 +268,28 @@
null,
null,
null,
2427,
2430,
null,
2427,
2430,
null,
null,
2363,
2375,
null,
2363,
1202,
1202,
2375,
1214,
1214,
null,
null,
null,
64,
55,
null,
null,
2427,
2430,
null,
2427,
2430,
null,
null,
39,
30,
1,
null,
null,
Expand All @@ -300,16 +300,16 @@
1,
null,
null,
38,
29,
null,
38,
29,
null,
null,
39,
30,
null,
null,
1,
2415,
2418,
null,
null,
1,
Expand Down Expand Up @@ -346,7 +346,7 @@
null,
null,
null,
2427,
2430,
null,
null,
null,
Expand Down Expand Up @@ -376,15 +376,15 @@
null,
null,
null,
1202,
1202,
1214,
1214,
null,
null,
null,
null,
1202,
1214,
null,
1201,
1213,
null,
null,
null
Expand Down Expand Up @@ -573,7 +573,7 @@
1,
null,
1,
1106,
1107,
null,
null,
1,
Expand Down Expand Up @@ -616,7 +616,6 @@
null,
null,
null,
null,
1,
0,
null,
Expand Down Expand Up @@ -859,6 +858,10 @@
null,
null,
1,
0,
null,
null,
1,
4,
null,
null,
Expand Down Expand Up @@ -949,9 +952,9 @@
null,
null,
1,
6166,
6057,
null,
4110,
4010,
null,
null,
1,
Expand Down Expand Up @@ -1003,9 +1006,9 @@
null,
null,
null,
5859,
5968,
null,
16686,
16892,
null,
null,
1,
Expand Down Expand Up @@ -1604,7 +1607,7 @@
1,
null,
1,
133,
134,
null,
null,
1,
Expand All @@ -1623,41 +1626,32 @@
null,
null,
null,
70,
18,
18,
18,
18,
18,
null,
null,
18,
null,
null,
null,
null,
null,
null,
null,
18,
null,
null,
null,
null,
null,
null,
null,
23,
null,
null,
142,
71,
71,
71,
71,
71,
71,
null,
null,
71,
null,
19,
19,
19,
null,
19,
24,
24,
168,
null,
24,
24,
null,
null,
18,
19,
null,
null,
1,
Expand Down Expand Up @@ -2995,7 +2989,7 @@
1,
null,
1,
1449,
1461,
null,
null,
1,
Expand Down Expand Up @@ -3592,10 +3586,6 @@
null,
null,
1,
0,
null,
null,
1,
null,
null,
null,
Expand Down Expand Up @@ -3659,6 +3649,6 @@
]
}
},
"timestamp": 1724317741
"timestamp": 1724833918
}
}
Loading

0 comments on commit c7c8ca8

Please sign in to comment.