Skip to content

Instantly share code, notes, and snippets.

@therod
Last active March 1, 2018 15:32
Show Gist options
  • Save therod/1a0a7d0bae0bd8ba961899294e48e8ed to your computer and use it in GitHub Desktop.
Save therod/1a0a7d0bae0bd8ba961899294e48e8ed to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'prawn'
class OrangeTree
def initialize
@height = 0
@orange_count = 0
@fruit = 0
@age = 0
@pdf = Prawn::Document.new
@pdf.image open("http://membership.drphillipschamber.org/wp-content/uploads/2017/04/OTGC-Logo-w-transparent-background.png"), at: [50, 450], width: 250
end
def write_to_pdf(text)
@pdf.text text
end
def write_pdf
File.write("orangetree.pdf", @pdf.render)
end
def one_year
if @height = @height.to_f + (rand 0.5 - 1.2) #growth per year
@age = @age + 1
@orange_count = 0
write_to_pdf "The tree is #{@age} years old and #{@height.round(2)}M tall"
if @age >= 2
@orange_count = (rand 1-10) * @age #amount of oranges for specific year
if @orange_count >= 1
write_to_pdf "The tree holds #{@orange_count} mighty fine oranges!"
if @age >= 2.5
@orange_count >= 1
@orange_count = @orange_count - 1 #you picked an orange
write_to_pdf "You just picked a delicious orange leaving #{@orange_count} oranges in the tree"
if @height >= 10
write_to_pdf "The tree died and there are no more oranges to pick"
end
end
end
end
end
end
end
tree = OrangeTree.new
5.times do
tree.one_year
end
tree.write_pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment