Class: Ruqqus::ItemBase Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ruqqus/types/item_base.rb

Overview

This class is abstract.

Base class for all all major API types.

Direct Known Subclasses

Guild, Submission, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#createdTime (readonly)

Returns the time the item was created.

Returns:

  • (Time)

    the time the item was created.



# File 'lib/ruqqus/types/item_base.rb', line 17

#created_utcInteger (readonly)

Returns the time the item was created, in seconds since the Unix epoch.

Returns:

  • (Integer)

    the time the item was created, in seconds since the Unix epoch.



# File 'lib/ruqqus/types/item_base.rb', line 13

#idString (readonly)

Returns a unique ID for this item.

Returns:

  • (String)

    a unique ID for this item.



# File 'lib/ruqqus/types/item_base.rb', line 21

Returns a relative link to this item.

Returns:

  • (String)

    a relative link to this item.



# File 'lib/ruqqus/types/item_base.rb', line 9

Class Method Details

.from_json(json) ⇒ Object

Loads the object from a JSON-formatted string.

Parameters:

  • json (String, Hash)

    a JSON string representing the object.

Returns:

  • (Object)

    the loaded object.



59
60
61
62
63
64
# File 'lib/ruqqus/types/item_base.rb', line 59

def self.from_json(json)
  obj = allocate
  data = json.is_a?(Hash) ? json : JSON.parse(json, symbolize_names: true)
  obj.instance_variable_set(:@data, data)
  obj
end

Instance Method Details

#==(other) ⇒ Boolean

Returns true if this object is equal to another, otherwise false.

Returns:

  • (Boolean)

    true if this object is equal to another, otherwise false.



33
34
35
# File 'lib/ruqqus/types/item_base.rb', line 33

def ==(other)
  self.class == other.class && id == other.id
end

#banned?Boolean

Returns true if item has been banned, otherwise false.

Returns:

  • (Boolean)

    true if item has been banned, otherwise false.



27
28
29
# File 'lib/ruqqus/types/item_base.rb', line 27

def banned?
  !!@data[:is_banned]
end