Class: Rubyhexagon::Tag::Implication

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyhexagon/tag/implication.rb,
lib/rubyhexagon/api/tag/implication.rb

Overview

A class to interact with the e621 web interface.

Author:

  • Maxine Michalski

Since:

  • 2.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(imply) ⇒ Object

Initializer for Implication.

Parameters:

  • imply (Hash)

    implication data, fetched from e621

Options Hash (imply):

  • :id (Integer)

    implication ID

  • :consequent_id (Integer)

    implying tag ID

  • :predicate_id (Integer)

    implied tag ID

  • :pending (TrueClass|FalseClass)

    statud

Raises:

  • InvalidIDError if implication ID is not valid

  • ArgumentError hash not valid

Author:

  • Maxine Michalski

Since:

  • 2.0.0



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

#idInteger (readonly)

Returns id of implication.

Returns:

  • (Integer)

    id of implication

Since:

  • 2.0.0



27
28
29
# File 'lib/rubyhexagon/tag/implication.rb', line 27

def id
  @id
end

#impliesE621::Tag (readonly)

Returns implied tag.

Returns:

Since:

  • 2.0.0



33
34
35
# File 'lib/rubyhexagon/tag/implication.rb', line 33

def implies
  @implies
end

#tagE621::Tag (readonly)

Returns implying tag.

Returns:

Since:

  • 2.0.0



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

Parameters:

  • query (Hash)

    Parameter for query

Returns:

  • (Array[E621::Tag::Implication])

Raises:

  • (ArgumentError)

Author:

  • Maxine Michalski

Since:

  • 2.0.0



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.

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 2.0.0



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.

Returns:

  • (TrueClass)

    tag implication is pending

  • (FalseClass)

    tag implication is not pending

Author:

  • Maxine Michalski

Since:

  • 2.0.0



86
87
88
# File 'lib/rubyhexagon/tag/implication.rb', line 86

def pending?
  @pending
end