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 aliased to.
-
#id ⇒ Integer
readonly
Id of alias.
-
#name ⇒ String
readonly
Name of alias.
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.
Constructor Details
#initialize(ali) ⇒ Object
Initializer for Alias.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubyhexagon/tag/alias.rb', line 49 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)
Returns tag this alias is aliased to.
33 34 35 |
# File 'lib/rubyhexagon/tag/alias.rb', line 33 def alias_to @alias_to end |
#id ⇒ Integer (readonly)
Returns id of alias.
27 28 29 |
# File 'lib/rubyhexagon/tag/alias.rb', line 27 def id @id end |
#name ⇒ String (readonly)
Returns name of alias.
30 31 32 |
# File 'lib/rubyhexagon/tag/alias.rb', line 30 def name @name end |
Class Method Details
.list(query) ⇒ Array[E621::Tag::Alias]
Fetch tag aliases
33 34 35 36 37 38 |
# File 'lib/rubyhexagon/api/tag/alias.rb', line 33 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.
72 73 74 |
# File 'lib/rubyhexagon/tag/alias.rb', line 72 def ==(other) other.is_a?(Alias) && @id == other.id end |
#pending? ⇒ TrueClass, FalseClass
Check if this alias is pending confirmation.
82 83 84 |
# File 'lib/rubyhexagon/tag/alias.rb', line 82 def pending? @pending end |