parliament-ruby 0.7.4 → 0.7.5.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/parliament.rb +0 -3
- data/lib/parliament/builder.rb +0 -1
- data/lib/parliament/builder/base_response_builder.rb +11 -2
- data/lib/parliament/request/base_request.rb +34 -23
- data/lib/parliament/request/url_request.rb +23 -5
- data/lib/parliament/response.rb +4 -128
- data/lib/parliament/response/base_response.rb +18 -0
- data/lib/parliament/version.rb +1 -1
- data/parliament-ruby.gemspec +1 -2
- metadata +20 -36
- data/lib/parliament/builder/ntriple_response_builder.rb +0 -25
- data/lib/parliament/decorator.rb +0 -27
- data/lib/parliament/decorator/constituency_area.rb +0 -27
- data/lib/parliament/decorator/constituency_group.rb +0 -92
- data/lib/parliament/decorator/contact_point.rb +0 -48
- data/lib/parliament/decorator/gender.rb +0 -13
- data/lib/parliament/decorator/gender_identity.rb +0 -13
- data/lib/parliament/decorator/house.rb +0 -41
- data/lib/parliament/decorator/house_incumbency.rb +0 -48
- data/lib/parliament/decorator/house_seat.rb +0 -27
- data/lib/parliament/decorator/incumbency.rb +0 -55
- data/lib/parliament/decorator/party.rb +0 -27
- data/lib/parliament/decorator/party_membership.rb +0 -34
- data/lib/parliament/decorator/person.rb +0 -188
- data/lib/parliament/decorator/postal_address.rb +0 -26
- data/lib/parliament/decorator/seat_incumbency.rb +0 -69
- data/lib/parliament/utils.rb +0 -135
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module Parliament
|
|
2
|
-
module Decorator
|
|
3
|
-
# Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/PartyMembership
|
|
4
|
-
module PartyMembership
|
|
5
|
-
# Alias partyMembershipHasParty with fallback.
|
|
6
|
-
#
|
|
7
|
-
# @return [Grom::Node, nil] the party of the Grom::Node or nil.
|
|
8
|
-
def party
|
|
9
|
-
respond_to?(:partyMembershipHasParty) ? partyMembershipHasParty.first : nil
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Alias partyMembershipStartDate with fallback.
|
|
13
|
-
#
|
|
14
|
-
# @return [DateTime, nil] the start date of the Grom::Node or nil.
|
|
15
|
-
def start_date
|
|
16
|
-
@start_date ||= respond_to?(:partyMembershipStartDate) ? DateTime.parse(partyMembershipStartDate) : nil
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Alias partyMembershipEndDate with fallback.
|
|
20
|
-
#
|
|
21
|
-
# @return [DateTime, nil] the end date of the Grom::Node or nil.
|
|
22
|
-
def end_date
|
|
23
|
-
@end_date ||= respond_to?(:partyMembershipEndDate) ? DateTime.parse(partyMembershipEndDate) : nil
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Checks if Grom::Node has an end date.
|
|
27
|
-
#
|
|
28
|
-
# @return [Boolean] a boolean depending on whether or not the Grom::Node has an end date.
|
|
29
|
-
def current?
|
|
30
|
-
end_date.nil?
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
module Parliament
|
|
2
|
-
module Decorator
|
|
3
|
-
# Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/Person.
|
|
4
|
-
# rubocop:disable ModuleLength
|
|
5
|
-
module Person
|
|
6
|
-
# Alias personGivenName with fallback.
|
|
7
|
-
#
|
|
8
|
-
# @return [String, String] the given name of the Grom::Node or an empty string.
|
|
9
|
-
def given_name
|
|
10
|
-
respond_to?(:personGivenName) ? personGivenName : ''
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Alias personFamilyName with fallback.
|
|
14
|
-
#
|
|
15
|
-
# @return [String, String] the family name of the Grom::Node or an empty string.
|
|
16
|
-
def family_name
|
|
17
|
-
respond_to?(:personFamilyName) ? personFamilyName : ''
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Alias personOtherNames with fallback.
|
|
21
|
-
#
|
|
22
|
-
# @return [String, String] the other names of the Grom::Node or an empty string.
|
|
23
|
-
def other_name
|
|
24
|
-
respond_to?(:personOtherNames) ? personOtherNames : ''
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Alias personDateOfBirth with fallback.
|
|
28
|
-
#
|
|
29
|
-
# @return [DateTime, nil] the date of birth of the Grom::Node or nil.
|
|
30
|
-
def date_of_birth
|
|
31
|
-
@date_of_birth ||= respond_to?(:personDateOfBirth) ? DateTime.parse(personDateOfBirth) : nil
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Builds a full name using personGivenName and personFamilyName.
|
|
35
|
-
#
|
|
36
|
-
# @return [String, String] the full name of the Grom::Node or an empty string.
|
|
37
|
-
def full_name
|
|
38
|
-
return @full_name unless @full_name.nil?
|
|
39
|
-
|
|
40
|
-
full_name = []
|
|
41
|
-
full_name << personGivenName if respond_to?(:personGivenName)
|
|
42
|
-
full_name << personFamilyName if respond_to?(:personFamilyName)
|
|
43
|
-
|
|
44
|
-
@full_name = full_name.join(' ')
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Alias memberHasIncumbency with fallback.
|
|
48
|
-
#
|
|
49
|
-
# @return [Array, Array] all the incumbencies of the Grom::Node or an empty array.
|
|
50
|
-
def incumbencies
|
|
51
|
-
respond_to?(:memberHasIncumbency) ? memberHasIncumbency : []
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Alias memberHasIncumbency with fallback.
|
|
55
|
-
#
|
|
56
|
-
# @return [Array, Array] the seat incumbencies of the Grom::Node or an empty array.
|
|
57
|
-
def seat_incumbencies
|
|
58
|
-
@seat_incumbencies ||= incumbencies.select { |inc| inc.type == 'http://id.ukpds.org/schema/SeatIncumbency' }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Alias memberHasIncumbency with fallback.
|
|
62
|
-
#
|
|
63
|
-
# @return [Array, Array] the house incumbencies of the Grom::Node or an empty array.
|
|
64
|
-
def house_incumbencies
|
|
65
|
-
@house_incumbencies ||= incumbencies.select { |inc| inc.type == 'http://id.ukpds.org/schema/HouseIncumbency' }
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# Alias seatIncumbencyHasHouseSeat with fallback.
|
|
69
|
-
#
|
|
70
|
-
# @return [Array, Array] the seats of the Grom::Node or an empty array.
|
|
71
|
-
def seats
|
|
72
|
-
@seats ||= seat_incumbencies.map(&:seat).flatten.uniq
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Alias houseSeatHasHouse with fallback.
|
|
76
|
-
#
|
|
77
|
-
# @return [Array, Array] the houses of the Grom::Node or an empty array.
|
|
78
|
-
def houses
|
|
79
|
-
@houses ||= [seats.map(&:house), house_incumbencies.map(&:house)].flatten.uniq
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# Alias houseSeatHasConstituencyGroup with fallback.
|
|
83
|
-
#
|
|
84
|
-
# @return [Array, Array] the constituencies of the Grom::Node or an empty array.
|
|
85
|
-
def constituencies
|
|
86
|
-
@constituencies ||= seats.map(&:constituency).flatten.uniq
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Alias partyMemberHasPartyMembership with fallback.
|
|
90
|
-
#
|
|
91
|
-
# @return [Array, Array] the party memberships of the Grom::Node or an empty array.
|
|
92
|
-
def party_memberships
|
|
93
|
-
respond_to?(:partyMemberHasPartyMembership) ? partyMemberHasPartyMembership : []
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# Alias partyMembershipHasParty with fallback.
|
|
97
|
-
#
|
|
98
|
-
# @return [Array, Array] the parties of the Grom::Node or an empty array.
|
|
99
|
-
def parties
|
|
100
|
-
@parties ||= party_memberships.map(&:party).flatten.uniq.compact
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# Alias personHasContactPoint with fallback.
|
|
104
|
-
#
|
|
105
|
-
# @return [Array, Array] the contact points of the Grom::Node or an empty array.
|
|
106
|
-
def contact_points
|
|
107
|
-
respond_to?(:personHasContactPoint) ? personHasContactPoint : []
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
# Alias personHasGenderIdentity with fallback.
|
|
111
|
-
#
|
|
112
|
-
# @return [Array, Array] the gender identities of the Grom::Node or an empty array.
|
|
113
|
-
def gender_identities
|
|
114
|
-
respond_to?(:personHasGenderIdentity) ? personHasGenderIdentity : []
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
# Alias genderIdentityHasGender with fallback.
|
|
118
|
-
#
|
|
119
|
-
# @return [Array, Array] the gender of the Grom::Node or nil.
|
|
120
|
-
def gender
|
|
121
|
-
gender_identities.empty? ? nil : gender_identities.first.gender
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
# Checks the statuses of the Grom::Node.
|
|
125
|
-
#
|
|
126
|
-
# @return [Hash, Hash] the statuses of the Grom::Node or an empty hash.
|
|
127
|
-
def statuses
|
|
128
|
-
return @statuses unless @statuses.nil?
|
|
129
|
-
|
|
130
|
-
statuses = {}
|
|
131
|
-
statuses[:house_membership_status] = house_membership_status
|
|
132
|
-
statuses[:general_membership_status] = general_membership_status
|
|
133
|
-
|
|
134
|
-
@statuses = statuses
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
# Alias D79B0BAC513C4A9A87C9D5AFF1FC632F with fallback.
|
|
138
|
-
#
|
|
139
|
-
# @return [String, String] the full title of the Grom::Node or an empty string.
|
|
140
|
-
def full_title
|
|
141
|
-
respond_to?(:D79B0BAC513C4A9A87C9D5AFF1FC632F) ? self.D79B0BAC513C4A9A87C9D5AFF1FC632F : ''
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
# Alias F31CBD81AD8343898B49DC65743F0BDF with fallback.
|
|
145
|
-
#
|
|
146
|
-
# @return [String, String] the display name of the Grom::Node or the full name.
|
|
147
|
-
def display_name
|
|
148
|
-
respond_to?(:F31CBD81AD8343898B49DC65743F0BDF) ? self.F31CBD81AD8343898B49DC65743F0BDF : full_name
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# Alias A5EE13ABE03C4D3A8F1A274F57097B6C with fallback.
|
|
152
|
-
#
|
|
153
|
-
# @return [String, String] the sort name of the Grom::Node or an empty string.
|
|
154
|
-
def sort_name
|
|
155
|
-
respond_to?(:A5EE13ABE03C4D3A8F1A274F57097B6C) ? self.A5EE13ABE03C4D3A8F1A274F57097B6C : ''
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
private
|
|
159
|
-
|
|
160
|
-
def house_membership_status
|
|
161
|
-
no_current_seat_incumbency = seat_incumbencies.select(&:current?).empty?
|
|
162
|
-
no_current_house_incumbency = house_incumbencies.select(&:current?).empty?
|
|
163
|
-
former_lord = (!house_incumbencies.empty? && no_current_house_incumbency)
|
|
164
|
-
former_mp = (!seat_incumbencies.empty? && no_current_seat_incumbency)
|
|
165
|
-
|
|
166
|
-
build_house_membership_status(no_current_seat_incumbency, no_current_house_incumbency, former_lord, former_mp)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
# TODO: Convert hard-coded strings to language file values
|
|
170
|
-
def build_house_membership_status(no_current_seat_incumbency, no_current_house_incumbency, former_lord, former_mp)
|
|
171
|
-
statuses = []
|
|
172
|
-
statuses << 'Current MP' unless no_current_seat_incumbency
|
|
173
|
-
statuses << 'Member of the House of Lords' unless no_current_house_incumbency
|
|
174
|
-
statuses << 'Former Member of the House of Lords' if former_lord
|
|
175
|
-
statuses << 'Former MP' if former_mp
|
|
176
|
-
|
|
177
|
-
statuses
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
def general_membership_status
|
|
181
|
-
statuses = []
|
|
182
|
-
statuses << 'Current Member' unless incumbencies.select(&:current?).empty?
|
|
183
|
-
statuses << 'Former Member' if !incumbencies.empty? && incumbencies.select(&:current?).empty?
|
|
184
|
-
statuses
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
end
|
|
188
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module Parliament
|
|
2
|
-
module Decorator
|
|
3
|
-
# Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/PostalAddress
|
|
4
|
-
module PostalAddress
|
|
5
|
-
# Builds a full address using the lines of the address and the postcode.
|
|
6
|
-
#
|
|
7
|
-
# @return [String, String] the full address of the Grom::Node or an empty string.
|
|
8
|
-
def full_address
|
|
9
|
-
address_array.join(', ')
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
|
|
14
|
-
def address_array
|
|
15
|
-
address_array = []
|
|
16
|
-
(1..5).each do |i|
|
|
17
|
-
if respond_to?("addressLine#{i}".to_sym)
|
|
18
|
-
address_array << instance_variable_get("@addressLine#{i}".to_sym)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
address_array << postCode if respond_to?(:postCode)
|
|
22
|
-
address_array
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
module Parliament
|
|
2
|
-
module Decorator
|
|
3
|
-
# Decorator namespace for Grom::Node instances with type: http://id.ukpds.org/schema/SeatIncumbency
|
|
4
|
-
module SeatIncumbency
|
|
5
|
-
# Alias incumbencyStartDate with fallback.
|
|
6
|
-
#
|
|
7
|
-
# @return [DateTime, nil] the start date of the Grom::Node or nil.
|
|
8
|
-
def start_date
|
|
9
|
-
respond_to?(:incumbencyStartDate) ? DateTime.parse(incumbencyStartDate) : nil
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Alias incumbencyEndDate with fallback.
|
|
13
|
-
#
|
|
14
|
-
# @return [DateTime, nil] the end date of the Grom::Node or nil.
|
|
15
|
-
def end_date
|
|
16
|
-
respond_to?(:incumbencyEndDate) ? DateTime.parse(incumbencyEndDate) : nil
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Alias seatIncumbencyHasHouseSeat with fallback.
|
|
20
|
-
#
|
|
21
|
-
# @return [Grom::Node, nil] the seat of the Grom::Node or nil.
|
|
22
|
-
def seat
|
|
23
|
-
respond_to?(:seatIncumbencyHasHouseSeat) ? seatIncumbencyHasHouseSeat.first : nil
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Checks if Grom::Node has no end date.
|
|
27
|
-
#
|
|
28
|
-
# @return [Boolean] a boolean depending on whether or not the Grom::Node has an end date.
|
|
29
|
-
def current?
|
|
30
|
-
!former?
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Checks if Grom::Node has an end date.
|
|
34
|
-
#
|
|
35
|
-
# @return [Boolean] a boolean depending on whether or not the Grom::Node has an end date.
|
|
36
|
-
def former?
|
|
37
|
-
respond_to?(:incumbencyEndDate)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Alias houseSeatHasHouse with fallback.
|
|
41
|
-
#
|
|
42
|
-
# @return [Grom::Node, nil] the house of the Grom::Node or nil.
|
|
43
|
-
def house
|
|
44
|
-
seat.nil? ? nil : seat.house
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
# Alias houseSeatHasConstituencyGroup with fallback.
|
|
48
|
-
#
|
|
49
|
-
# @return [Grom::Node, nil] the constituency of the Grom::Node or nil.
|
|
50
|
-
def constituency
|
|
51
|
-
seat.nil? ? nil : seat.constituency
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# Alias incumbencyHasContactPoint with fallback.
|
|
55
|
-
#
|
|
56
|
-
# @return [Array, Array] the contact points of the Grom::Node or an empty array.
|
|
57
|
-
def contact_points
|
|
58
|
-
respond_to?(:incumbencyHasContactPoint) ? incumbencyHasContactPoint : []
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Alias incumbencyHasMember with fallback.
|
|
62
|
-
#
|
|
63
|
-
# @return [Grom::Node, nil] the member connected to the Grom::Node or nil.
|
|
64
|
-
def member
|
|
65
|
-
respond_to?(:incumbencyHasMember) ? incumbencyHasMember.first : nil
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
data/lib/parliament/utils.rb
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
module Parliament
|
|
2
|
-
# Namespace for helper methods used with parliament-ruby.
|
|
3
|
-
#
|
|
4
|
-
# @since 0.6.0
|
|
5
|
-
module Utils
|
|
6
|
-
# Sort an Array of Objects in ascending order. The major difference between this implementation of sort_by and the
|
|
7
|
-
# standard one is that our implementation includes objects that return nil for our parameter values.
|
|
8
|
-
#
|
|
9
|
-
# @see Parliament::Utils.reverse_sort_by
|
|
10
|
-
#
|
|
11
|
-
# @example Sorting a list of objects by date
|
|
12
|
-
# response = parliament.people('123').get.filter('http://id.ukpds.org/schema/Person')
|
|
13
|
-
#
|
|
14
|
-
# objects = response.first.incumbencies
|
|
15
|
-
#
|
|
16
|
-
# args = {
|
|
17
|
-
# list: objects,
|
|
18
|
-
# parameters: [:endDate],
|
|
19
|
-
# prepend_rejected: false
|
|
20
|
-
# }
|
|
21
|
-
#
|
|
22
|
-
# sorted_list = Parliament::Util.sort_by(args)
|
|
23
|
-
#
|
|
24
|
-
# sorted_list.each { |incumbency| puts incumbency.respond_to?(:endDate) ? incumbency.endDate : 'Current' }
|
|
25
|
-
# # http://id.ukpds.org/1121 - 1981-07-31
|
|
26
|
-
# # http://id.ukpds.org/5678 - 1991-03-15
|
|
27
|
-
# # http://id.ukpds.org/1234 - 1997-01-01
|
|
28
|
-
# # http://id.ukpds.org/9101 - 2011-09-04
|
|
29
|
-
# # http://id.ukpds.org/3141 - Current
|
|
30
|
-
#
|
|
31
|
-
# @param [Hash] args a hash of arguments.
|
|
32
|
-
# @option args [Array<Object>] :list the 'list' which we are sorting.
|
|
33
|
-
# @option args [Array<Symbol>] :parameters an array of parameters we are sorting by.
|
|
34
|
-
# @option args [Boolean] :prepend_rejected (true) should objects that do not respond to our parameters be prepended?
|
|
35
|
-
#
|
|
36
|
-
# @return [Array<Object>] a sorted array of objects using the args passed in.
|
|
37
|
-
def self.sort_by(args)
|
|
38
|
-
rejected = []
|
|
39
|
-
args = sort_defaults.merge(args)
|
|
40
|
-
list = args[:list].dup
|
|
41
|
-
parameters = args[:parameters]
|
|
42
|
-
|
|
43
|
-
list, rejected = prune_list(list, rejected, parameters)
|
|
44
|
-
|
|
45
|
-
list = sort_list(list, parameters)
|
|
46
|
-
|
|
47
|
-
# Any rejected (nil) values will be added to the start of the result unless specified otherwise
|
|
48
|
-
args[:prepend_rejected] ? rejected.concat(list) : list.concat(rejected)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Sort an Array of Objects in descending order. Largely, this implementation runs Parliament::Utils.sort_by and
|
|
52
|
-
# calls reverse! on the result.
|
|
53
|
-
#
|
|
54
|
-
# @see Parliament::Utils.sort_by
|
|
55
|
-
#
|
|
56
|
-
# @example Sorting a list of objects by date
|
|
57
|
-
# response = parliament.people('123').get.filter('http://id.ukpds.org/schema/Person')
|
|
58
|
-
#
|
|
59
|
-
# objects = response.first.incumbencies
|
|
60
|
-
#
|
|
61
|
-
# args = {
|
|
62
|
-
# list: objects,
|
|
63
|
-
# parameters: [:endDate],
|
|
64
|
-
# prepend_rejected: false
|
|
65
|
-
# }
|
|
66
|
-
#
|
|
67
|
-
# sorted_list = Parliament::Util.reverse_sort_by(args)
|
|
68
|
-
#
|
|
69
|
-
# sorted_list.each { |incumbency| puts incumbency.respond_to?(:endDate) ? incumbency.endDate : 'Current' }
|
|
70
|
-
# # http://id.ukpds.org/3141 - Current
|
|
71
|
-
# # http://id.ukpds.org/9101 - 2011-09-04
|
|
72
|
-
# # http://id.ukpds.org/1234 - 1997-01-01
|
|
73
|
-
# # http://id.ukpds.org/5678 - 1991-03-15
|
|
74
|
-
# # http://id.ukpds.org/1121 - 1981-07-31
|
|
75
|
-
#
|
|
76
|
-
# @param [Hash] args a hash of arguments.
|
|
77
|
-
# @option args [Array<Object>] :list the 'list' which we are sorting.
|
|
78
|
-
# @option args [Array<Symbol>] :parameters an array of parameters we are sorting by.
|
|
79
|
-
# @option args [Boolean] :prepend_rejected (true) should objects that do not respond to our parameters be prepended?
|
|
80
|
-
#
|
|
81
|
-
# @return [Array<Object>] a sorted array of objects using the args passed in.
|
|
82
|
-
def self.reverse_sort_by(args)
|
|
83
|
-
Parliament::Utils.sort_by(args).reverse!
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# Default arguments hash for #sort_by and #reverse_sort_by.
|
|
87
|
-
#
|
|
88
|
-
# @see Parliament::Utils.sort_by
|
|
89
|
-
# @see Parliament::Utils.reverse_sort_by
|
|
90
|
-
#
|
|
91
|
-
# @return [Hash] default arguments used in sorting methods.
|
|
92
|
-
def self.sort_defaults
|
|
93
|
-
{ prepend_rejected: true }
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
# @!method self.prune_list(list, rejected, parameters)
|
|
97
|
-
# Prune all objects that do not respond to a given array of parameters.
|
|
98
|
-
#
|
|
99
|
-
# @private
|
|
100
|
-
# @!scope class
|
|
101
|
-
# @!visibility private
|
|
102
|
-
#
|
|
103
|
-
# @param [Array<Object>] list the 'list' of objects we are pruning from.
|
|
104
|
-
# @param [Array<Object>] rejected the objects we have pruned from list.
|
|
105
|
-
# @param [Array<Symbol>] parameters an array of parameters we are checking.
|
|
106
|
-
#
|
|
107
|
-
# @return [Array<Array<Object>, Array<Object>>] an array containing first, the pruned list and secondly, the rejected list.
|
|
108
|
-
private_class_method def self.prune_list(list, rejected, parameters)
|
|
109
|
-
list.delete_if do |object|
|
|
110
|
-
rejected << object unless parameters.all? { |param| !object.send(param).nil? if object.respond_to?(param) }
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
[list, rejected]
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
# @!method self.sort_list(list, parameters)
|
|
117
|
-
# Sort a given list of objects by a list of parameters.
|
|
118
|
-
#
|
|
119
|
-
# @private
|
|
120
|
-
# @!scope class
|
|
121
|
-
# @!visibility private
|
|
122
|
-
#
|
|
123
|
-
# @param [Array<Object>] list the 'list' of objects we are pruning from.
|
|
124
|
-
# @param [Array<Symbol>] parameters an array of parameters we are checking.
|
|
125
|
-
#
|
|
126
|
-
# @return [Array<Object>] our sorted list.
|
|
127
|
-
private_class_method def self.sort_list(list, parameters)
|
|
128
|
-
list.sort_by! do |object|
|
|
129
|
-
parameters.map do |param|
|
|
130
|
-
object.send(param).is_a?(String) ? I18n.transliterate(object.send(param)).downcase : object.send(param)
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|