Class: Eventify::Provider::Base

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/eventify/provider/base.rb

Direct Known Subclasses

ApolloKino, Livenation, Piletilevi

Constant Summary collapse

MissingAttributeError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
19
# File 'lib/eventify/provider/base.rb', line 14

def initialize(event)
  @id = event[:id] or raise MissingAttributeError.new("id is missing")
  @title = event[:title] or raise MissingAttributeError.new("title is missing")
  @link = event[:link] or raise MissingAttributeError.new("link is missing")
  @date = event[:date]
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



12
13
14
# File 'lib/eventify/provider/base.rb', line 12

def date
  @date
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/eventify/provider/base.rb', line 12

def id
  @id
end

Returns the value of attribute link.



12
13
14
# File 'lib/eventify/provider/base.rb', line 12

def link
  @link
end

#titleObject (readonly)

Returns the value of attribute title.



12
13
14
# File 'lib/eventify/provider/base.rb', line 12

def title
  @title
end

Class Method Details

.fetchObject

Raises:

  • (NotImplementedError)


7
8
9
# File 'lib/eventify/provider/base.rb', line 7

def fetch
  raise NotImplementedError
end

Instance Method Details

#<=>(other) ⇒ Object



48
49
50
# File 'lib/eventify/provider/base.rb', line 48

def <=>(other)
  title <=> other.title
end

#==(other) ⇒ Object Also known as: eql?



34
35
36
37
38
39
40
# File 'lib/eventify/provider/base.rb', line 34

def ==(other)
  id == other.id &&
    provider == other.provider &&
    title == other.title &&
    link == other.link &&
    date.to_i == other.date.to_i
end

#exists?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/eventify/provider/base.rb', line 30

def exists?
  Database.exists? self
end

#hashObject



44
45
46
# File 'lib/eventify/provider/base.rb', line 44

def hash
  "#{id}-#{provider}-#{title}-#{link}-#{date.to_i}".hash
end

#providerObject



21
22
23
# File 'lib/eventify/provider/base.rb', line 21

def provider
  @provider ||= self.class.name
end

#saveObject



25
26
27
28
# File 'lib/eventify/provider/base.rb', line 25

def save
  Database.save self 
  self
end