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 ⇒ Time
readonly
Creation time of tag item.
-
#id ⇒ Integer
readonly
Tag item ID.
-
#post ⇒ E621::Post
readonly
Post for this tag item.
-
#sources ⇒ Array<String>
readonly
New sources for post in tag item.
-
#tags ⇒ Array<E621::Tags>
readonly
Changed tags inside tag item.
Class Method Summary collapse
-
.list(query) ⇒ Array<E621::TagItem>
Fetch a list of tag items.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for tag change items.
-
#initialize(tag_item) ⇒ Object
constructor
Initializer for tag change items.
-
#to_hash ⇒ Hash
Turn object into a hash representation of itself.
Constructor Details
#initialize(tag_item) ⇒ Object
Initializer for tag change items
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 67 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 ⇒ Time (readonly)
Creation time of tag item
37 38 39 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 37 def created_at @created_at end |
#id ⇒ Integer (readonly)
Tag item ID
31 32 33 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 31 def id @id end |
#post ⇒ E621::Post (readonly)
Post for this tag item
43 44 45 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 43 def post @post end |
#sources ⇒ Array<String> (readonly)
New sources for post in tag item
55 56 57 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 55 def sources @sources end |
#tags ⇒ Array<E621::Tags> (readonly)
Changed tags inside tag item
49 50 51 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 49 def @tags end |
Class Method Details
.list(query) ⇒ Array<E621::TagItem>
Fetch a list of tag items
35 36 37 38 39 40 41 42 |
# File 'lib/rubyhexagon/api/post/tag_item.rb', line 35 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
94 95 96 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 94 def ==(other) other.is_a?(E621::Post::TagItem) && @id == other.id end |
#to_hash ⇒ Hash
Turn object into a hash representation of itself
105 106 107 108 109 110 111 |
# File 'lib/rubyhexagon/post/tag_item.rb', line 105 def to_hash hash = {} instance_variables.each do |i| hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i)) end hash end |