-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data completeness subview class #15432
base: master
Are you sure you want to change the base?
Changes from all commits
1ce1435
9a2597f
dbbbb06
957a37e
6c986ad
6a2538c
53a8d0d
c1b8f24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
# The completeness of each type of member data as a percentage | ||
class DataCompleteness | ||
# @param [Array<PersonCard>] | ||
def initialize(person_cards:) | ||
@person_cards = person_cards | ||
end | ||
|
||
CARDS = %i(social bio contacts identifiers).freeze | ||
Percentages = Struct.new(*CARDS) | ||
# The percentage of data completeness for categories defined in CARDS | ||
# @return [struct DataCompleteness::Percentages] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you see somewhere that you should be including this |
||
def percentages | ||
Percentages.new(*CARDS.map { |card| completeness(card) }) | ||
end | ||
|
||
private | ||
|
||
attr_reader :person_cards | ||
|
||
def completeness(card) | ||
((person_cards.count { |p| p.send(card.to_s).any? } / person_cards.count.to_f) * 100).floor | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really a query method, but it's named as if it's a command method. (See, for example, http://martinfowler.com/bliki/CommandQuerySeparation.html) Methods that are returning you something should simply be named for what they return, not what they do to return that — so here just calling this |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
Percentages
class isn't documented…