Class: Songdrop::Base

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

Direct Known Subclasses

Artist, Drop, Error, Errors, Like, Mix, Play, Song, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(properties = {}) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/songdrop/objects/base.rb', line 5

def initialize(properties={})
  @_properties = properties
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/songdrop/objects/base.rb', line 9

def method_missing(method, *args, &block)
  method = $1 if method =~ /(\S+)\?/
  method = method.to_sym
  result = @_properties[method]
  result = Time.at(result.to_i) if result and method =~ /_at/
  result = Time.at(result.to_i).to_date if result and method =~ /_on/
  result
end

Instance Attribute Details

#_propertiesObject (readonly)

Returns the value of attribute _properties.



3
4
5
# File 'lib/songdrop/objects/base.rb', line 3

def _properties
  @_properties
end

Instance Method Details

#errors?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/songdrop/objects/base.rb', line 18

def errors?
  !self.errors.nil?
end