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
Id of implication.
-
#implies ⇒ E621::Tag
readonly
Implied tag.
-
#tag ⇒ E621::Tag
readonly
Implying 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.
Constructor Details
#initialize(imply) ⇒ Object
Initializer for Implication.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubyhexagon/tag/implication.rb', line 49 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)
Returns id of implication.
27 28 29 |
# File 'lib/rubyhexagon/tag/implication.rb', line 27 def id @id end |
#implies ⇒ E621::Tag (readonly)
Returns implied tag.
33 34 35 |
# File 'lib/rubyhexagon/tag/implication.rb', line 33 def implies @implies end |
#tag ⇒ E621::Tag (readonly)
Returns implying tag.
30 31 32 |
# File 'lib/rubyhexagon/tag/implication.rb', line 30 def tag @tag end |
Class Method Details
.list(query) ⇒ Array[E621::Tag::Implication]
Fetch tag implications
33 34 35 36 37 38 |
# File 'lib/rubyhexagon/api/tag/implication.rb', line 33 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.
76 77 78 |
# File 'lib/rubyhexagon/tag/implication.rb', line 76 def ==(other) other.is_a?(Implication) && @id == other.id end |
#pending? ⇒ TrueClass, FalseClass
Check if this implication is pending confirmation.
86 87 88 |
# File 'lib/rubyhexagon/tag/implication.rb', line 86 def pending? @pending end |