Skip to content
Browse files

Refactored method for clarity

  • Loading branch information...
1 parent 037919e commit b64c0cdc2c4efdaffd2ad72d1ee75147458764df @maxfliri maxfliri committed Jan 22, 2013
Showing with 12 additions and 8 deletions.
  1. +12 −8 lib/response/insidegov_weekly_policy_entries_response.rb
View
20 lib/response/insidegov_weekly_policy_entries_response.rb
@@ -15,7 +15,7 @@ def initialize(response, config_class)
def create_messages response_as_hash
rows = (response_as_hash["rows"] or [])
- condense_to_one_week(rows).map { |slug, entries|
+ collect_by_slug(rows).map { |slug, entries|
create_message({
start_at: extract_start_at(response_as_hash["query"]["start-date"]),
end_at: extract_end_at(response_as_hash["query"]["end-date"]),
@@ -28,13 +28,17 @@ def create_messages response_as_hash
}
end
- def condense_to_one_week rows
- rows.
- map { |week, slug, entries| [slug, entries.to_i] }.
- group_by { |slug, entries| slug }.
- map { |slug, array|
- [slug, array.map { |slug, entries| entries }.reduce(&:+)]
- }
+ def collect_by_slug rows
+ entries_by_slug = discard_week(rows).group_by { |slug, _| slug }
+ sum_entries(entries_by_slug)
+ end
+
+ def sum_entries(entries_by_slug)
+ entries_by_slug.map { |slug, array| [slug, array.map { |_, entries| entries }.reduce(&:+)] }
+ end
+
+ def discard_week(rows)
+ rows.map { |_, slug, entries| [slug, entries.to_i] }
end
end
end

0 comments on commit b64c0cd

Please sign in to comment.
Something went wrong with that request. Please try again.