Class: Eventify::Provider::Base

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

Direct Known Subclasses

FBI, Piletilevi, SolarisKino, Ticketpro

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



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

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

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



34
35
36
# File 'lib/eventify/provider/base.rb', line 34

def ==(other)
  id == other.id && provider == other.provider && title == other.title
end

#exists?Boolean

Returns:

  • (Boolean)


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

def exists?
  Database.exists? self
end

#hashObject



40
41
42
# File 'lib/eventify/provider/base.rb', line 40

def hash
  "#{id}-#{provider}-#{link}-#{title}".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