Last active
May 11, 2019 20:10
-
-
Save brandonbloom/d52e04408631e796e870e390bc03bad3 to your computer and use it in GitHub Desktop.
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
module Model | |
def initialize(attributes) | |
self.attributes = attributes | |
end | |
def attributes=(hash) | |
hash.each do |k, v| | |
send :"#{k}=", v | |
end | |
end | |
end | |
def sanitize_html(s) | |
s.strip #todo | |
end | |
class Feed | |
include Model | |
attr_accessor :title | |
attr_reader :description, :published_at | |
def description=(value) | |
@description = sanitize_html(value) | |
end | |
def published_at=(value) | |
case value | |
when Time | |
@published_at = value | |
when String | |
@published_at = Time.new(value) | |
when nil | |
@published_at = nil | |
else | |
raise 'bad value' | |
end | |
end | |
end | |
Feed.new(title: 'hey', description: ' a great story ', published_at: Time.now) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment