Class: E621::Artist

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

Overview

Class to hold information about an artist on e621

Author:

  • Maxine Michalski

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(artist) ⇒ Object

Initializer for Artist.

Parameters:

  • artist (Hash)

    artist data, fetched from e621

Author:

  • Maxine Michalski

Since:

  • 1.0.0



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

def initialize(artist)
  @name = artist
end

Instance Attribute Details

#alternative_namesArray<String> (readonly)

Returns alternative names for artist.

Returns:

  • (Array<String>)

    alternative names for artist

Since:

  • 1.0.0



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

def alternative_names
  @alternative_names
end

#idInteger (readonly)

Returns id of artist.

Returns:

  • (Integer)

    id of artist

Since:

  • 1.0.0



24
25
26
# File 'lib/rubyhexagon/artist.rb', line 24

def id
  @id
end

#nameString (readonly)

Returns name of artist.

Returns:

  • (String)

    name of artist

Since:

  • 1.0.0



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

def name
  @name
end

#urlsArray<URI> (readonly)

Returns links to find artist.

Returns:

  • (Array<URI>)

    links to find artist

Since:

  • 1.0.0



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

def urls
  @urls
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Comparison method for artists

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



73
74
75
76
77
78
79
80
# File 'lib/rubyhexagon/artist.rb', line 73

def ==(other)
  return false unless other.is_a?(Artist)
  if @id && other.id
    @id == other.id && @name == other.name
  else
    @name == other.name
  end
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?
  @active
end

#showArtist

Returns a filled Artist object

Returns:

  • (Artist)

    filled out artist object

Author:

  • Maxine Michalski

Since:

  • 1.0.0



62
63
64
65
66
# File 'lib/rubyhexagon/artist.rb', line 62

def show
  artist = Artist.new(@name)
  artist.show!
  artist
end

#show!Object

Fills this object with additional artist data

Author:

  • Maxine Michalski

Since:

  • 1.0.0



49
50
51
52
53
54
55
# File 'lib/rubyhexagon/artist.rb', line 49

def show!
  artist = API.new.fetch('artist', 'index', name: @name).first
  @id = artist[:id].to_i
  @alternative_names = artist[:other_names].split(/,\s+/)
  @urls = artist[:urls].map { |u| URI(u) }
  @active = artist[:is_active]
end