Class: Rubyhexagon::Tag::Alias
- Inherits:
-
Object
- Object
- Rubyhexagon::Tag::Alias
- Defined in:
- lib/rubyhexagon/tag/alias.rb,
lib/rubyhexagon/api/tag/alias.rb
Overview
A class to interact with the e621 web interface.
Instance Attribute Summary collapse
-
#alias_to ⇒ E621::Tag
readonly
Tag this alias is for.
-
#id ⇒ Integer
readonly
Alias ID.
-
#name ⇒ String
readonly
Alias name.
Class Method Summary collapse
-
.list(query) ⇒ Array[E621::Tag::Alias]
Fetch tag aliases.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Types, to give a more meaningful comparison.
-
#initialize(ali) ⇒ Object
constructor
Initializer for Alias.
-
#pending? ⇒ TrueClass, FalseClass
Check if this alias is pending confirmation.
-
#to_hash ⇒ Hash
Turn object into a hash representation of itself.
Constructor Details
#initialize(ali) ⇒ Object
Initializer for Alias
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rubyhexagon/tag/alias.rb', line 61 def initialize(ali) raise ArgumentError, "#{ali.class} is not a Hash" unless ali.is_a?(Hash) if ali.keys != %i[id name alias_id pending] mis = %i[id name alias_id pending] - ali.keys raise ArgumentError, "Missing key#{mis.count > 1 ? 's' : ''}: #{mis}" end ali.each do |k, v| if %i[id name pending].include?(k) if k == :id && !(v.is_a?(Integer) && v.positive?) raise InvalidIDError, "Invalid id: #{v}" end instance_variable_set("@#{k}".to_sym, v) elsif k == :alias_id @alias_to = E621::Tag.new(id: v) end end end |
Instance Attribute Details
#alias_to ⇒ E621::Tag (readonly)
Tag this alias is for
43 44 45 |
# File 'lib/rubyhexagon/tag/alias.rb', line 43 def alias_to @alias_to end |
#id ⇒ Integer (readonly)
Alias ID
31 32 33 |
# File 'lib/rubyhexagon/tag/alias.rb', line 31 def id @id end |
#name ⇒ String (readonly)
Alias name
37 38 39 |
# File 'lib/rubyhexagon/tag/alias.rb', line 37 def name @name end |
Class Method Details
.list(query) ⇒ Array[E621::Tag::Alias]
Fetch tag aliases
38 39 40 41 42 43 |
# File 'lib/rubyhexagon/api/tag/alias.rb', line 38 def self.list(query) raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash) E621::API.fetch(:tag_alias, :index, query).map do |tag| new(tag) end end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Types, to give a more meaningful comparison
85 86 87 |
# File 'lib/rubyhexagon/tag/alias.rb', line 85 def ==(other) other.is_a?(Alias) && @id == other.id end |
#pending? ⇒ TrueClass, FalseClass
Check if this alias is pending confirmation
96 97 98 |
# File 'lib/rubyhexagon/tag/alias.rb', line 96 def pending? @pending end |
#to_hash ⇒ Hash
Turn object into a hash representation of itself
107 108 109 110 111 112 113 |
# File 'lib/rubyhexagon/tag/alias.rb', line 107 def to_hash hash = {} instance_variables.each do |i| hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i)) end hash end |