Class: Rubyhexagon::Artist
- Inherits:
-
Object
- Object
- Rubyhexagon::Artist
- Defined in:
- lib/rubyhexagon/artist.rb,
lib/rubyhexagon/api/artist.rb
Overview
A class to interact with the e621 web interface.
Instance Attribute Summary collapse
-
#group_name ⇒ String
readonly
Group name for artist.
-
#id ⇒ Integer
readonly
Id of artist.
-
#name ⇒ String
readonly
Name of artist.
-
#other_names ⇒ Array<String>
readonly
Alternative names for artist.
-
#updater ⇒ E621::User
readonly
Updating user.
-
#urls ⇒ Array<URI>
readonly
Links to find artist.
-
#version ⇒ Integer
readonly
Version of artist information.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for artists.
-
#active? ⇒ TrueClass, FalseClass
Check if this artist is active.
-
#initialize(artist) ⇒ Object
constructor
Initializer for Artist.
Constructor Details
#initialize(artist) ⇒ Object
Initializer for Artist.
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_name ⇒ String (readonly)
Returns group name for artist.
35 36 37 |
# File 'lib/rubyhexagon/artist.rb', line 35 def group_name @group_name end |
#id ⇒ Integer (readonly)
Returns id of artist.
26 27 28 |
# File 'lib/rubyhexagon/artist.rb', line 26 def id @id end |
#name ⇒ String (readonly)
Returns name of artist.
29 30 31 |
# File 'lib/rubyhexagon/artist.rb', line 29 def name @name end |
#other_names ⇒ Array<String> (readonly)
Returns alternative names for artist.
32 33 34 |
# File 'lib/rubyhexagon/artist.rb', line 32 def other_names @other_names end |
#updater ⇒ E621::User (readonly)
Returns updating user.
44 45 46 |
# File 'lib/rubyhexagon/artist.rb', line 44 def updater @updater end |
#urls ⇒ Array<URI> (readonly)
Returns links to find artist.
38 39 40 |
# File 'lib/rubyhexagon/artist.rb', line 38 def urls @urls end |
#version ⇒ Integer (readonly)
Returns version of artist information.
41 42 43 |
# File 'lib/rubyhexagon/artist.rb', line 41 def version @version end |
Class Method Details
.list(query) ⇒ Object
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
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
88 89 90 |
# File 'lib/rubyhexagon/artist.rb', line 88 def active? @is_active end |