Skip to content

Instantly share code, notes, and snippets.

@brianbancroft
Created March 29, 2016 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianbancroft/b1158aad2f68a89f50f9fd7a2e85c39a to your computer and use it in GitHub Desktop.
Save brianbancroft/b1158aad2f68a89f50f9fd7a2e85c39a to your computer and use it in GitHub Desktop.
#banner_print.rb
$tax_rate = 0.15
$colour_rate_breakpoint = 2
$colour_cost_low = 10
$colour_cost_high = 15
$cost_pr_sqft = 15
#single function
def calculate_cost(dim_x, dim_y, num_colours)
price = calculate_tax(calculate_area_cost(dim_x, dim_y) + colour_cost(num_colours))
end
#Supporting Features
def calculate_tax(cost)
cost = cost * ($tax_rate + 1)
end
def calculate_area_cost(length, width)
cost = length * width * $cost_pr_sqft
end
def colour_cost(n_colours)
cost = n_colours <= $colour_rate_breakpoint ? n_colours * $colour_cost_low : n_colours * $colour_cost_high
end
puts calculate_cost(1,2,3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment