Class: Rubyhexagon::Post::TagItem

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyhexagon/post/tag_item.rb,
lib/rubyhexagon/api/post/tag_item.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(tag_item) ⇒ Object

Initializer for tag change items

Parameters:

  • tag_item (Hash)

    tag item data

Author:

  • Maxine Michalski

Since:

  • 2.0.0



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rubyhexagon/post/tag_item.rb', line 44

def initialize(tag_item)
  unless tag_item.is_a?(Hash)
    raise ArgumentError, "#{tag_item.class} is not a Hash"
  end
  unless (miss = %i[id created_at post_id tags source] -
      tag_item.keys).empty?
    raise ArgumentError, 'Not all required keys available! '\
      "Missing: #{miss}"
  end
  id = tag_item[:id]
  unless id.is_a?(Integer) && id.positive?
    raise InvalidIDError, "ID out of range: #{id}"
  end
  @id = id
  @created_at = Time.at(tag_item[:created_at])
  @post = E621::Post.new(id: tag_item[:post_id])
  @tags = tag_item[:tags].split(' ').map { |t| E621::Tag.new(name: t) }
  @sources = tag_item[:source].split($INPUT_RECORD_SEPARATOR)
end

Instance Attribute Details

#created_atInteger (readonly)

Returns id of post information.

Returns:

  • (Integer)

    id of post information

Since:

  • 2.0.0



29
30
31
# File 'lib/rubyhexagon/post/tag_item.rb', line 29

def created_at
  @created_at
end

#idInteger (readonly)

Returns id of post information.

Returns:

  • (Integer)

    id of post information

Since:

  • 2.0.0



27
28
29
# File 'lib/rubyhexagon/post/tag_item.rb', line 27

def id
  @id
end

#postInteger (readonly)

Returns id of post information.

Returns:

  • (Integer)

    id of post information

Since:

  • 2.0.0



31
32
33
# File 'lib/rubyhexagon/post/tag_item.rb', line 31

def post
  @post
end

#sourcesInteger (readonly)

Returns id of post information.

Returns:

  • (Integer)

    id of post information

Since:

  • 2.0.0



35
36
37
# File 'lib/rubyhexagon/post/tag_item.rb', line 35

def sources
  @sources
end

#tagsInteger (readonly)

Returns id of post information.

Returns:

  • (Integer)

    id of post information

Since:

  • 2.0.0



33
34
35
# File 'lib/rubyhexagon/post/tag_item.rb', line 33

def tags
  @tags
end

Class Method Details

.list(query) ⇒ Object

Since:

  • 2.0.0



26
27
28
29
30
31
32
33
# File 'lib/rubyhexagon/api/post/tag_item.rb', line 26

def self.list(query)
  unless query.is_a?(Hash)
    raise ArgumentError, 'A Hash or Post object is required'
  end
  E621::API.fetch(:post_tag_history, :index, query).map do |note|
    new(note)
  end
end

Instance Method Details

#==(other) ⇒ TrueClass, FalseClass

Comparison method for tag change items

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 2.0.0



69
70
71
# File 'lib/rubyhexagon/post/tag_item.rb', line 69

def ==(other)
  other.is_a?(E621::Post::TagItem) && @id == other.id
end