Use metaprogramming to refactor three similar methods into one

Following [this comment](https://github.com/google/WebFundamentals/blob/a27b6fa42f88110fca749fca9a2b82ab01c1cd1e/src/site/_plugins/sample_builder.rb#L26) I refactored the three methods into one using metaprogramming. This solution might hurt code readability, but it's more concise.

(Sorry for resubmitting! I promise I won't trash my master branch this time.)