Skip to content

Instantly share code, notes, and snippets.

@radar
Forked from tra38/datatemplate.rb
Last active January 13, 2016 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radar/ea263abd49a18f90a694 to your computer and use it in GitHub Desktop.
Save radar/ea263abd49a18f90a694 to your computer and use it in GitHub Desktop.
This is a class.
class DataTemplate
attr_reader :data, :narrative
attr_accessor :name, :address
def initialize(data_hash)
data_hash.each do |key, value|
self.send("#{key}=", value)
end
@data = data_hash
write_narrative
end
def write_narrative
#user writes in what should happened next
raise "There is no 'write_narrative' method."
end
def write(condition, klass_a, klass_b = nil)
@narrative ||= []
if condition
@narrative << klass_a.new.generate
elsif klass_b
@narrative << klass_b.new.generate
else
end
end
def publish
@narrative.join(" ")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment