Class: Arcticelvis::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/arcticelvis/base.rb

Direct Known Subclasses

Event, EventMessage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Initializes the object using the given attributes

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes to use for initialization



9
10
11
12
# File 'lib/arcticelvis/base.rb', line 9

def initialize(attributes = {})
  set_attributes(attributes)
  parse_timestamps
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'lib/arcticelvis/base.rb', line 4

def created_at
  @created_at
end

#updated_atObject

Returns the value of attribute updated_at.



4
5
6
# File 'lib/arcticelvis/base.rb', line 4

def updated_at
  @updated_at
end

Instance Method Details

#parse_timestampsObject

Parses UNIX timestamps and creates Time objects.



24
25
26
27
# File 'lib/arcticelvis/base.rb', line 24

def parse_timestamps
  @created_at = DateTime.parse(created_at) if created_at
  @updated_at = DateTime.parse(updated_at) if updated_at
end

#set_attributes(attributes) ⇒ Object

Sets the attributes

Parameters:

  • attributes (Hash)

    The attributes to initialize



17
18
19
20
21
# File 'lib/arcticelvis/base.rb', line 17

def set_attributes(attributes)
  attributes.each_pair do |key, value|
    instance_variable_set("@#{key}", value)
  end
end