Class: YiffSpace::Images::Avatar::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yiffspace/images/avatar/base.rb

Direct Known Subclasses

Discord, Gravatar

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/yiffspace/images/avatar/base.rb', line 11

def initialize(id, type)
  @id   = id
  @type = type
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/yiffspace/images/avatar/base.rb', line 9

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/yiffspace/images/avatar/base.rb', line 9

def type
  @type
end

Class Method Details

.from_json(data) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
# File 'lib/yiffspace/images/avatar/base.rb', line 28

def self.from_json(data)
  raise(ArgumentError, "invalid data") if data.blank?

  data = JSON.parse(data) if data.is_a?(String)
  data = ::YiffSpace::Utils::OpenHash.from(data)

  return Avatar.find_type(data.type).from_json(data) if self == Base

  new(data.id)
end

.typeObject



7
# File 'lib/yiffspace/images/avatar/base.rb', line 7

def self.type = nil

Instance Method Details

#serializable_hashObject



24
25
26
# File 'lib/yiffspace/images/avatar/base.rb', line 24

def serializable_hash(*)
  { "id" => @id, "type" => @type }
end

#updateObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/yiffspace/images/avatar/base.rb', line 20

def update(*)
  raise(NotImplementedError)
end

#urlObject

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/yiffspace/images/avatar/base.rb', line 16

def url
  raise(NotImplementedError)
end