Skip to content

Instantly share code, notes, and snippets.

@egardner
Created February 4, 2016 02:23
Show Gist options
  • Save egardner/639cfb81238490716b43 to your computer and use it in GitHub Desktop.
Save egardner/639cfb81238490716b43 to your computer and use it in GitHub Desktop.
Assignment Branch Condition
# Get Catalogue Sections
# Returns 3 arrays of resource objects (frontmatter, catalogue, backmatter)
def catalogue_sections
contents = sort_catalogue_contents
frontmatter = contents.find_all { |p| p.data.sort_order <= 10 }
backmatter = contents.find_all { |p| p.data.sort_order > 100 }
catalogue = contents.find_all do |p|
p.data.sort_order > 10 && p.data.sort_order <= 100
end
frontmatter.sort_by! { |p| p.data.sort_order }
catalogue.sort_by! { |p| p.data.sort_order }
backmatter.sort_by! { |p| p.data.sort_order }
return frontmatter, catalogue, backmatter
end
@egardner
Copy link
Author

egardner commented Feb 4, 2016

I'm writing a Helper Method in the Middleman static site generator.
I've started using Rubocop in an attempt to write higher-quality code, and I keep getting the following warning:

Assignment Branch Condition size for catalogue_sections is too high. [25.34/15]

Can anyone explain (in non-computer science jargon) what this actually means?

@jonas054
Copy link

jonas054 commented Feb 6, 2016

It means that your method is too big, that it's doing too much. In this case one could argue that it contains too much duplication.

A bit computer sciency, but here's the definition: http://c2.com/cgi/wiki?AbcMetric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment