Class: Rubyhexagon::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



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

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



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

def alternative_names
  @alternative_names
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

#urlsArray<URI> (readonly)

Returns links to find artist.

Returns:

  • (Array<URI>)

    links to find artist

Since:

  • 1.0.0



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

def urls
  @urls
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Comparison method for artists

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 1.0.0



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

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



90
91
92
# File 'lib/rubyhexagon/artist.rb', line 90

def active?
  @active
end

#showArtist

Returns a filled Artist object

Returns:

  • (Artist)

    filled out artist object

Author:

  • Maxine Michalski

Since:

  • 1.0.0



64
65
66
67
68
# File 'lib/rubyhexagon/artist.rb', line 64

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



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

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