aboutsummaryrefslogtreecommitdiffstats
path: root/lib/events.rb
blob: e647930f992fdb913f6c2e361dbb6ac1b5bb28b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'time'

module Events
  class Event

    attr_reader :start_time
    attr_reader :duration
    attr_reader :title
    attr_reader :venue
    attr_reader :image_url

    def initialize(attrs)
      @start_time = Time.parse(attrs['start_time'])
      @duration = attrs['duration'].to_i
      @title = attrs['title']
      @venue = attrs['venue']
      @image_url = attrs['image'] unless attrs['image'].length < 10
    end

    def date
      @start_time.to_date
    end

    def slug
      "#{start_time.to_i}-#{title.downcase.gsub(/[^a-z0-9_-]/, '')}"
    end
  end
end