Class: Rubyhexagon::Type Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class to hold type information.

Author:

  • Maxine Michalski

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, locked) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializer for Type.

Parameters:

  • type (Hash)

    type data, fetched from e621

Raises:

  • ArgumentError if type ID is not valid

Author:

  • Maxine Michalski

Since:

  • 1.0.0



43
44
45
46
47
48
49
50
# File 'lib/rubyhexagon/type.rb', line 43

def initialize(id, locked)
  unless [0, 1, 3, 4, 5].include?(id)
    raise ArgumentError, "Unkown type id: #{id}"
  end
  @id     = id.to_i
  @name   = [:general, :artist, nil, :copyright, :character, :species][@id]
  @locked = locked ? true : false
end

Instance Attribute Details

#idInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns id of type.

Returns:

  • (Integer)

    id of type

Since:

  • 1.0.0



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

def id
  @id
end

#nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns name of type.

Returns:

  • (String)

    name of type

Since:

  • 1.0.0



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

def name
  @name
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Comparison method for Types, to give a more meaningful comparison.

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



57
58
59
60
# File 'lib/rubyhexagon/type.rb', line 57

def ==(other)
  other.is_a?(Type) && @id == other.id && @name == other.name &&
    @locked == other.locked?
end

#locked?TrueClass, FalseClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if this type is locked for the tag who has it assigned.

Returns:

  • (TrueClass)

    tag type is locked

  • (FalseClass)

    tag type is not locked

Author:

  • Maxine Michalski

Since:

  • 1.0.0



68
69
70
# File 'lib/rubyhexagon/type.rb', line 68

def locked?
  @locked
end