Class: Rubyhexagon::Tag::Implication
- Inherits:
-
Object
- Object
- Rubyhexagon::Tag::Implication
- Defined in:
- lib/rubyhexagon/tag/implication.rb,
lib/rubyhexagon/api/tag/implication.rb
Overview
A class to interact with the e621 web interface.
Instance Attribute Summary collapse
-
#id ⇒ Integer
readonly
Implication ID.
-
#implies ⇒ E621::Tag
readonly
Tag that is implied.
-
#tag ⇒ E621::Tag
readonly
Tag that implies another tag.
Class Method Summary collapse
-
.list(query) ⇒ Array[E621::Tag::Implication]
Fetch tag implications.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Types, to give a more meaningful comparison.
-
#initialize(imply) ⇒ Object
constructor
Initializer for Implication.
-
#pending? ⇒ TrueClass, FalseClass
Check if this implication is pending confirmation.
-
#to_hash ⇒ Hash
Turn object into a hash representation of itself.
Constructor Details
#initialize(imply) ⇒ Object
Initializer for Implication
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rubyhexagon/tag/implication.rb', line 61 def initialize(imply) unless imply.is_a?(Hash) raise ArgumentError, "#{imply.class} is not a Hash" end if imply.keys != %i[id consequent_id predicate_id pending] mis = %i[id consequent_id predicate_id pending] - imply.keys raise ArgumentError, "Missing key#{mis.count > 1 ? 's' : ''}: #{mis}" end imply.each do |k, v| if %i[id 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 == :consequent_id @tag = E621::Tag.new(id: v) elsif k == :predicate_id @implies = E621::Tag.new(id: v) end end end |
Instance Attribute Details
#id ⇒ Integer (readonly)
Implication ID
31 32 33 |
# File 'lib/rubyhexagon/tag/implication.rb', line 31 def id @id end |
#implies ⇒ E621::Tag (readonly)
Tag that is implied
43 44 45 |
# File 'lib/rubyhexagon/tag/implication.rb', line 43 def implies @implies end |
#tag ⇒ E621::Tag (readonly)
Tag that implies another tag
37 38 39 |
# File 'lib/rubyhexagon/tag/implication.rb', line 37 def tag @tag end |
Class Method Details
.list(query) ⇒ Array[E621::Tag::Implication]
Fetch tag implications
38 39 40 41 42 43 |
# File 'lib/rubyhexagon/api/tag/implication.rb', line 38 def self.list(query) raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash) E621::API.fetch(:tag_implication, :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
89 90 91 |
# File 'lib/rubyhexagon/tag/implication.rb', line 89 def ==(other) other.is_a?(Implication) && @id == other.id end |
#pending? ⇒ TrueClass, FalseClass
Check if this implication is pending confirmation
101 102 103 |
# File 'lib/rubyhexagon/tag/implication.rb', line 101 def pending? @pending end |
#to_hash ⇒ Hash
Turn object into a hash representation of itself
112 113 114 115 116 117 118 |
# File 'lib/rubyhexagon/tag/implication.rb', line 112 def to_hash hash = {} instance_variables.each do |i| hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i)) end hash end |