Class: RMeetup::Type::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/rmeetup/type/event.rb

Overview

RMeetup::Type::Event

Data wraper for a Event fethcing response Used to access result attributes as well as progammatically fetch relative data types based on this event.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event = {}) ⇒ Event

Returns a new instance of Event.



12
13
14
# File 'lib/rmeetup/type/event.rb', line 12

def initialize(event = {})
  @event = event
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rmeetup/type/event.rb', line 18

def method_missing(id, *args)
  if event.has_key?(id.id2name)
    event[id.id2name]
  else
    fail NoMethodError.new('no method')
  end
end

Instance Attribute Details

#eventObject (readonly) Also known as: to_h

Returns the value of attribute event.



15
16
17
# File 'lib/rmeetup/type/event.rb', line 15

def event
  @event
end

Instance Method Details

#idObject

Special accessors that need typecasting or other parsing



27
28
29
# File 'lib/rmeetup/type/event.rb', line 27

def id
  event['id'].to_i
end

#latObject



30
31
32
# File 'lib/rmeetup/type/event.rb', line 30

def lat
  event['lat'].to_f
end

#lonObject



33
34
35
# File 'lib/rmeetup/type/event.rb', line 33

def lon
  event['lon'].to_f
end

#rsvpcountObject



36
37
38
# File 'lib/rmeetup/type/event.rb', line 36

def rsvpcount
  event['rsvpcount'].to_i
end

#timeObject



42
43
44
# File 'lib/rmeetup/type/event.rb', line 42

def time
  Time.at(self.event['time']/1000).to_datetime
end

#updatedObject



39
40
41
# File 'lib/rmeetup/type/event.rb', line 39

def updated
  DateTime.parse(self.event['updated'])
end

#venueObject



45
46
47
# File 'lib/rmeetup/type/event.rb', line 45

def venue
  OpenStruct.new( self.event['venue'] )
end