Class: Rubyhexagon::Tag::Alias

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyhexagon/tag/alias.rb,
lib/rubyhexagon/api/tag/alias.rb

Overview

A class to interact with the e621 web interface.

Author:

  • Maxine Michalski

Since:

  • 2.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ali) ⇒ Object

Initializer for Alias.

Parameters:

  • ali (Hash)

    alias data, fetched from e621

Options Hash (ali):

  • :id (Integer)

    alias ID

  • :name (String)

    alias for tag

  • :alias_id (Integer)

    ID of tag to alias

  • :pending (TrueClass|FalseClass)

    statud

Raises:

  • InvalidIDError if alias ID is not valid

  • ArgumentError hash not valid

Author:

  • Maxine Michalski

Since:

  • 2.0.0



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubyhexagon/tag/alias.rb', line 49

def initialize(ali)
  raise ArgumentError, "#{ali.class} is not a Hash" unless ali.is_a?(Hash)
  if ali.keys != %i[id name alias_id pending]
    mis = %i[id name alias_id pending] - ali.keys
    raise ArgumentError, "Missing key#{mis.count > 1 ? 's' : ''}: #{mis}"
  end
  ali.each do |k, v|
    if %i[id name pending].include?(k)
      if k == :id && !(v.is_a?(Integer) && v.positive?)
        raise InvalidIDError, "Invalid id: #{v}"
      end
      instance_variable_set("@#{k}".to_sym, v)
    elsif k == :alias_id
      @alias_to = E621::Tag.new(id: v)
    end
  end
end

Instance Attribute Details

#alias_toE621::Tag (readonly)

Returns tag this alias is aliased to.

Returns:

  • (E621::Tag)

    tag this alias is aliased to

Since:

  • 2.0.0



33
34
35
# File 'lib/rubyhexagon/tag/alias.rb', line 33

def alias_to
  @alias_to
end

#idInteger (readonly)

Returns id of alias.

Returns:

  • (Integer)

    id of alias

Since:

  • 2.0.0



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

def id
  @id
end

#nameString (readonly)

Returns name of alias.

Returns:

  • (String)

    name of alias

Since:

  • 2.0.0



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

def name
  @name
end

Class Method Details

.list(query) ⇒ Array[E621::Tag::Alias]

Fetch tag aliases

Parameters:

  • query (Hash)

    Parameter for query

Returns:

  • (Array[E621::Tag::Alias])

Raises:

  • (ArgumentError)

Author:

  • Maxine Michalski

Since:

  • 2.0.0



33
34
35
36
37
38
# File 'lib/rubyhexagon/api/tag/alias.rb', line 33

def self.list(query)
  raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
  E621::API.fetch(:tag_alias, :index, query).map do |tag|
    new(tag)
  end
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

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

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 2.0.0



72
73
74
# File 'lib/rubyhexagon/tag/alias.rb', line 72

def ==(other)
  other.is_a?(Alias) && @id == other.id
end

#pending?TrueClass, FalseClass

Check if this alias is pending confirmation.

Returns:

  • (TrueClass)

    tag alias is pending

  • (FalseClass)

    tag alias is not pending

Author:

  • Maxine Michalski

Since:

  • 2.0.0



82
83
84
# File 'lib/rubyhexagon/tag/alias.rb', line 82

def pending?
  @pending
end