Last active
August 29, 2015 14:05
-
-
Save olvap/973de1c3f782feb3d2a6 to your computer and use it in GitHub Desktop.
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 Plantilla | |
attr_accessor :body, :title, :strategy | |
def initialize strategy | |
@strategy = strategy.new(self) | |
end | |
def to_s | |
@strategy.output | |
end | |
end | |
class Format | |
def initialize plantilla | |
@plantilla = plantilla | |
end | |
end | |
class FormatHtml < Format | |
def output | |
"<html> | |
<head> | |
#{ format_title } | |
</head> | |
<body> | |
#{ format_body } | |
</body> | |
</html>" | |
end | |
def format_title | |
"<h1> #{ @plantilla.title } </h1>" | |
end | |
def format_body | |
@plantilla.body.join("</br>") | |
end | |
end | |
class FormatPlainText < Format | |
def output | |
"#{ format_title }#{ format_body }" | |
end | |
def format_title | |
@plantilla.title | |
end | |
def format_body | |
@plantilla.body.join("\n") | |
end | |
end | |
p = Plantilla.new FormatHtml | |
p.title = 'Hello World!' | |
p.body = ['What', 'a', 'nice', 'day!'] | |
puts p | |
p = Plantilla.new FormatPlainText | |
p.title = 'Hello World!' | |
p.body = ['What', 'a', 'nice', 'day!'] | |
puts p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment