Class: Rubyhexagon::Artist

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyhexagon/artist.rb,
lib/rubyhexagon/api/artist.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(artist) ⇒ Object

Initializer for Artist.

Parameters:

  • artist (Hash)

    artist data

Author:

  • Maxine Michalski

Since:

  • 1.0.0



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rubyhexagon/artist.rb', line 53

def initialize(artist)
  unless artist.is_a?(Hash)
    raise ArgumentError, "#{artist.class} is not a Hash"
  end
  if artist[:id].nil? && artist[:name].nil?
    raise ArgumentError, 'At least :id or :name must be given!'
  end
  artist.each do |k, v|
    if %i[id name group_name version is_active].include?(k)
      if k == :id && !(v.is_a?(Integer) && v.positive?)
        raise InvalidIDError, "ID out of range: #{v}"
      end
      instance_variable_set("@#{k}".to_sym, v)
    elsif %i[other_names urls updater_id].include?(k)
      __send__("setup_#{k}".to_sym, v)
    end
  end
end

Instance Attribute Details

#group_nameString (readonly)

Returns group name for artist.

Returns:

  • (String)

    group name for artist

Since:

  • 1.0.0



35
36
37
# File 'lib/rubyhexagon/artist.rb', line 35

def group_name
  @group_name
end

#idInteger (readonly)

Returns id of artist.

Returns:

  • (Integer)

    id of artist

Since:

  • 1.0.0



26
27
28
# File 'lib/rubyhexagon/artist.rb', line 26

def id
  @id
end

#nameString (readonly)

Returns name of artist.

Returns:

  • (String)

    name of artist

Since:

  • 1.0.0



29
30
31
# File 'lib/rubyhexagon/artist.rb', line 29

def name
  @name
end

#other_namesArray<String> (readonly)

Returns alternative names for artist.

Returns:

  • (Array<String>)

    alternative names for artist

Since:

  • 1.0.0



32
33
34
# File 'lib/rubyhexagon/artist.rb', line 32

def other_names
  @other_names
end

#updaterE621::User (readonly)

Returns updating user.

Returns:

Since:

  • 1.0.0



44
45
46
# File 'lib/rubyhexagon/artist.rb', line 44

def updater
  @updater
end

#urlsArray<URI> (readonly)

Returns links to find artist.

Returns:

  • (Array<URI>)

    links to find artist

Since:

  • 1.0.0



38
39
40
# File 'lib/rubyhexagon/artist.rb', line 38

def urls
  @urls
end

#versionInteger (readonly)

Returns version of artist information.

Returns:

  • (Integer)

    version of artist information

Since:

  • 1.0.0



41
42
43
# File 'lib/rubyhexagon/artist.rb', line 41

def version
  @version
end

Class Method Details

.list(query) ⇒ Object

Raises:

  • (ArgumentError)

Since:

  • 2.0.0



25
26
27
28
29
30
# File 'lib/rubyhexagon/api/artist.rb', line 25

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

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Comparison method for artists

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



77
78
79
80
# File 'lib/rubyhexagon/artist.rb', line 77

def ==(other)
  return false unless other.is_a?(Artist)
  @id == other.id && @name == other.name && @version == other.version
end

#active?TrueClass, FalseClass

Check if this artist is active

Returns:

  • (TrueClass)

    artist is active

  • (FalseClass)

    artist is not active

Author:

  • Maxine Michalski

Since:

  • 1.0.0



88
89
90
# File 'lib/rubyhexagon/artist.rb', line 88

def active?
  @is_active
end