Created
October 29, 2013 02:28
-
-
Save octosteve/7208248 to your computer and use it in GitHub Desktop.
Solution from conditionals class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UpvoteCalculator | |
attr_reader :story, :category | |
def initialize story, category | |
@story = story | |
@category = category | |
end | |
def upvotes | |
upvotes = 1 | |
downcased_story = @story.downcase | |
if downcased_story.include? 'cats' | |
upvotes *= 5 | |
elsif downcased_story.include? 'bacon' | |
upvotes *= 8 | |
end | |
if @category.downcase.include? 'food' | |
upvotes *= 3 | |
end | |
upvotes | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment