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
Artist ID.
-
#name ⇒ String
readonly
Artist name.
-
#other_names ⇒ Array<String>
readonly
Alternative names for artist.
-
#updater ⇒ E621::User
readonly
Updating user for this artist.
-
#urls ⇒ Array<URI>
readonly
URLs to find artist.
-
#version ⇒ Integer
readonly
Version of artist information.
Class Method Summary collapse
-
.list(query) ⇒ Array<E621::Artist>
Fetch a list of artists.
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.
-
#to_hash ⇒ Hash
Turn object into a hash representation of itself.
Constructor Details
#initialize(artist) ⇒ Object
Initializer for Artist
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rubyhexagon/artist.rb', line 77 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)
Group name for artist
48 49 50 |
# File 'lib/rubyhexagon/artist.rb', line 48 def group_name @group_name end |
#id ⇒ Integer (readonly)
Artist ID
30 31 32 |
# File 'lib/rubyhexagon/artist.rb', line 30 def id @id end |
#name ⇒ String (readonly)
Artist name
36 37 38 |
# File 'lib/rubyhexagon/artist.rb', line 36 def name @name end |
#other_names ⇒ Array<String> (readonly)
Alternative names for artist
42 43 44 |
# File 'lib/rubyhexagon/artist.rb', line 42 def other_names @other_names end |
#updater ⇒ E621::User (readonly)
Updating user for this artist
66 67 68 |
# File 'lib/rubyhexagon/artist.rb', line 66 def updater @updater end |
#urls ⇒ Array<URI> (readonly)
URLs to find artist
54 55 56 |
# File 'lib/rubyhexagon/artist.rb', line 54 def urls @urls end |
#version ⇒ Integer (readonly)
Version of artist information
60 61 62 |
# File 'lib/rubyhexagon/artist.rb', line 60 def version @version end |
Class Method Details
.list(query) ⇒ Array<E621::Artist>
Fetch a list of artists
35 36 37 38 39 40 |
# File 'lib/rubyhexagon/api/artist.rb', line 35 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
102 103 104 105 |
# File 'lib/rubyhexagon/artist.rb', line 102 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
113 114 115 |
# File 'lib/rubyhexagon/artist.rb', line 113 def active? @is_active end |
#to_hash ⇒ Hash
Turn object into a hash representation of itself
124 125 126 127 128 129 130 |
# File 'lib/rubyhexagon/artist.rb', line 124 def to_hash hash = {} instance_variables.each do |i| hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i)) end hash end |