-
-
Save radar/ea263abd49a18f90a694 to your computer and use it in GitHub Desktop.
This is a class.
This file contains 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 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