Class: Rubyhexagon::Post::TagItem
- Inherits:
-
Object
- Object
- Rubyhexagon::Post::TagItem
- 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.
Instance Attribute Summary collapse
-
#created_at ⇒ Integer
readonly
Id of post information.
-
#id ⇒ Integer
readonly
Id of post information.
-
#post ⇒ Integer
readonly
Id of post information.
-
#sources ⇒ Integer
readonly
Id of post information.
-
#tags ⇒ Integer
readonly
Id of post information.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for tag change items.
-
#initialize(tag_item) ⇒ Object
constructor
Initializer for tag change items.
Constructor Details
#initialize(tag_item) ⇒ Object
Initializer for tag change items
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_at ⇒ Integer (readonly)
Returns id of post information.
29 30 31 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 29 def created_at @created_at end |
#id ⇒ Integer (readonly)
Returns id of post information.
27 28 29 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 27 def id @id end |
#post ⇒ Integer (readonly)
Returns id of post information.
31 32 33 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 31 def post @post end |
#sources ⇒ Integer (readonly)
Returns id of post information.
35 36 37 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 35 def sources @sources end |
#tags ⇒ Integer (readonly)
Returns id of post information.
33 34 35 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 33 def @tags end |
Class Method Details
.list(query) ⇒ Object
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
69 70 71 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 69 def ==(other) other.is_a?(E621::Post::TagItem) && @id == other.id end |