Skip to content

Instantly share code, notes, and snippets.

@brandonbloom
Last active May 11, 2019 20:10
Show Gist options
  • Save brandonbloom/d52e04408631e796e870e390bc03bad3 to your computer and use it in GitHub Desktop.
Save brandonbloom/d52e04408631e796e870e390bc03bad3 to your computer and use it in GitHub Desktop.
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