SHARE
TWEET

Untitled

a guest May 22nd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Model
  2.   def initialize(attributes)
  3.     self.attributes = attributes
  4.   end
  5.  
  6.   def attributes=(hash)
  7.     hash.each do |k, v|
  8.       send :"#{k}=", v
  9.     end
  10.   end
  11. end
  12.  
  13. def sanitize_html(s)
  14.   s.strip #todo
  15. end
  16.  
  17. class Feed
  18.   include Model
  19.  
  20.   attr_accessor :title
  21.  
  22.   attr_reader :description, :published_at
  23.  
  24.   def description=(value)
  25.     @description = sanitize_html(value)
  26.   end
  27.  
  28.   def published_at=(value)
  29.     case value
  30.     when Time
  31.       @published_at = value
  32.     when String
  33.       @published_at = Time.new(value)
  34.     when nil
  35.       @published_at = nil
  36.     else
  37.       raise 'bad value'
  38.     end
  39.   end
  40. end
  41.  
  42. Feed.new(title: 'hey', description: ' a great story ', published_at: Time.now)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top