rubyhexagon 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/rubyhexagon.rb +6 -26
- data/lib/rubyhexagon/api.rb +14 -7
- data/lib/rubyhexagon/api/post.rb +4 -71
- data/lib/rubyhexagon/post.rb +111 -257
- data/lib/rubyhexagon/post/{image.rb → file.rb} +30 -39
- data/lib/rubyhexagon/{api/post/flag.rb → post/preview.rb} +24 -14
- data/lib/rubyhexagon/post/sample.rb +65 -0
- data/lib/rubyhexagon/{api/post/tag_item.rb → post/score.rb} +32 -17
- metadata +7 -26
- data/lib/rubyhexagon/api/artist.rb +0 -42
- data/lib/rubyhexagon/api/pool.rb +0 -80
- data/lib/rubyhexagon/api/post/note.rb +0 -77
- data/lib/rubyhexagon/api/tag.rb +0 -71
- data/lib/rubyhexagon/api/tag/alias.rb +0 -46
- data/lib/rubyhexagon/api/tag/implication.rb +0 -46
- data/lib/rubyhexagon/api/user.rb +0 -67
- data/lib/rubyhexagon/artist.rb +0 -166
- data/lib/rubyhexagon/pool.rb +0 -151
- data/lib/rubyhexagon/post/flag.rb +0 -116
- data/lib/rubyhexagon/post/note.rb +0 -174
- data/lib/rubyhexagon/post/tag_item.rb +0 -114
- data/lib/rubyhexagon/search/posts.rb +0 -116
- data/lib/rubyhexagon/tag.rb +0 -109
- data/lib/rubyhexagon/tag/alias.rb +0 -116
- data/lib/rubyhexagon/tag/implication.rb +0 -121
- data/lib/rubyhexagon/tag/type.rb +0 -94
- data/lib/rubyhexagon/user.rb +0 -117
- data/lib/rubyhexagon/user/level.rb +0 -102
data/lib/rubyhexagon/pool.rb
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
# This class holds post information, fetched from e621, and gives access in a
|
21
|
-
# more Ruby like manner.
|
22
|
-
#
|
23
|
-
# @author Maxine Michalski
|
24
|
-
# @api public
|
25
|
-
# @since 1.4.0
|
26
|
-
class Pool
|
27
|
-
# Pool ID
|
28
|
-
# @example Get pool ID
|
29
|
-
# pool.id #=> Integer
|
30
|
-
# @return [Integer] returns this pool's ID
|
31
|
-
attr_reader :id
|
32
|
-
|
33
|
-
# Pool name
|
34
|
-
# @example Get pool name
|
35
|
-
# pool.name #=> String
|
36
|
-
# @return [String] returns name of current pool
|
37
|
-
attr_reader :name
|
38
|
-
|
39
|
-
# Pool creation time
|
40
|
-
# @example Get pool creation time
|
41
|
-
# pool.created_at #=> Time
|
42
|
-
# @return [Time] returns creation time
|
43
|
-
attr_reader :created_at
|
44
|
-
|
45
|
-
# Time of last update to pool
|
46
|
-
# @example Get last update time of pool
|
47
|
-
# pool.updated_at #=> Time
|
48
|
-
# @return [Time] returns time of last update
|
49
|
-
attr_reader :updated_at
|
50
|
-
|
51
|
-
# Pool description
|
52
|
-
# @example Get pool description
|
53
|
-
# pool.description #=> String
|
54
|
-
# @return [String] returns a description of the current pool
|
55
|
-
attr_reader :description
|
56
|
-
|
57
|
-
# Number of posts, inside pool
|
58
|
-
# @example Get number of posts, pool has
|
59
|
-
# pool.post_count #=> Integer
|
60
|
-
# @return [Integer] returns number of posts inside pool
|
61
|
-
attr_reader :post_count
|
62
|
-
|
63
|
-
# User who created pool
|
64
|
-
# @example Get user that created pool
|
65
|
-
# pool.creator #=> E621::User
|
66
|
-
# @return [E621::User] returns the user, who has created this pool
|
67
|
-
attr_reader :creator
|
68
|
-
|
69
|
-
# Posts of pool
|
70
|
-
#
|
71
|
-
# @example Get posts of pool
|
72
|
-
# pool.posts #=> Array<E621::Post>
|
73
|
-
# @return [Array<E621::Post>] returns an array of posts, that belong to
|
74
|
-
# this pool
|
75
|
-
attr_reader :posts
|
76
|
-
|
77
|
-
# @author Maxine Michalski
|
78
|
-
#
|
79
|
-
# Initializer for Pool objects
|
80
|
-
#
|
81
|
-
# @param pool [Hash] Pool information
|
82
|
-
# @example Get new pool instance
|
83
|
-
# E621::Pool.new(id: 1) #=> E621::Pool instance
|
84
|
-
# @return the object
|
85
|
-
def initialize(pool)
|
86
|
-
raise ArgumentError, "#{pool.class} is not a Hash" unless pool.is_a?(Hash)
|
87
|
-
raise ArgumentError, 'Hash must include :id' if pool[:id].nil?
|
88
|
-
pool.each do |k, v|
|
89
|
-
if %i[id name post_count is_active is_locked description].include?(k)
|
90
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
91
|
-
raise InvalidIDError, "ID out of range: #{v}"
|
92
|
-
end
|
93
|
-
instance_variable_set("@#{k}".to_sym, v)
|
94
|
-
elsif %i[updated_at created_at].include?(k)
|
95
|
-
instance_variable_set("@#{k}".to_sym, Time.at(v[:s]))
|
96
|
-
elsif k == :user_id
|
97
|
-
@creator = E621::User.new(id: v)
|
98
|
-
elsif k == :posts
|
99
|
-
@posts = v.map { |post| E621::Post.new(post) }
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
# @author Maxine Michalski
|
105
|
-
#
|
106
|
-
# Returns locking status
|
107
|
-
# @example Test if pool is locked
|
108
|
-
# pool.locked? #=> true or false
|
109
|
-
# @return [TrueClass|FalseClass]
|
110
|
-
def locked?
|
111
|
-
@is_locked
|
112
|
-
end
|
113
|
-
|
114
|
-
# @author Maxine Michalski
|
115
|
-
#
|
116
|
-
# Returns active status
|
117
|
-
# @example Test if pool is active or not
|
118
|
-
# pool.active? #=> true or false
|
119
|
-
# @return [TrueClass|FalseClass]
|
120
|
-
def active?
|
121
|
-
@is_active
|
122
|
-
end
|
123
|
-
|
124
|
-
# @author Maxine Michalski
|
125
|
-
#
|
126
|
-
# Comparison method for Pool objects
|
127
|
-
#
|
128
|
-
# @param other [Object] other object to compare
|
129
|
-
# @example Comapring two unequal pools
|
130
|
-
# Pool.new(id: 1) == Pool.new(id: 2) #=> false
|
131
|
-
# @return [TrueClass|FalseClass]
|
132
|
-
def ==(other)
|
133
|
-
other.is_a?(Pool) && @id == other.id && @updated_at == other.updated_at
|
134
|
-
end
|
135
|
-
|
136
|
-
# @author Maxine Michalski
|
137
|
-
#
|
138
|
-
# Turn object into a hash representation of itself
|
139
|
-
#
|
140
|
-
# @example Turn a User into a Hash
|
141
|
-
# E621::Pool.new(id: 1).to_hash #=> { id: 1 }
|
142
|
-
# @return [Hash]
|
143
|
-
def to_hash
|
144
|
-
hash = {}
|
145
|
-
instance_variables.each do |i|
|
146
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
147
|
-
end
|
148
|
-
hash
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
class Post
|
21
|
-
# Class to represent post flags
|
22
|
-
#
|
23
|
-
# @author Maxine Michalski
|
24
|
-
# @api public
|
25
|
-
# @since 2.0.0
|
26
|
-
class Flag
|
27
|
-
# Flag ID
|
28
|
-
# @example Get flag ID
|
29
|
-
# flag.id #=> Integer
|
30
|
-
# @return [Integer] id of flag
|
31
|
-
attr_reader :id
|
32
|
-
|
33
|
-
# Creation time of flag
|
34
|
-
# @example Get flag creation time
|
35
|
-
# flag.created_at #=> Time
|
36
|
-
# @return [Time] creation time of flag
|
37
|
-
attr_reader :created_at
|
38
|
-
|
39
|
-
# Flag post
|
40
|
-
# @example Get post that this flag references
|
41
|
-
# flag.post #=> E621::Post
|
42
|
-
# @return [621::Post] Post this flag is addressed to
|
43
|
-
attr_reader :post
|
44
|
-
|
45
|
-
# Flagging reason
|
46
|
-
# @example Get reason for flagging
|
47
|
-
# flag.reason #=> String
|
48
|
-
# @return [String] reason for flag
|
49
|
-
attr_reader :reason
|
50
|
-
|
51
|
-
# User that initiated flagging
|
52
|
-
# @example Get user that flagged post
|
53
|
-
# flag.user #=> E621::User
|
54
|
-
# @return [E621::User] User who flagged
|
55
|
-
attr_reader :user
|
56
|
-
|
57
|
-
# @author Maxine Michalski
|
58
|
-
#
|
59
|
-
# Initializer for flags
|
60
|
-
#
|
61
|
-
# @param flag [Hash] flag data
|
62
|
-
#
|
63
|
-
# @example Get instance of flag
|
64
|
-
# E621::Post::Flag.new(id: 1) #=> E621::Post::Flag instance
|
65
|
-
# @return the object
|
66
|
-
def initialize(flag)
|
67
|
-
unless flag.is_a?(Hash)
|
68
|
-
raise ArgumentError, "#{flag.class} is not a Hash"
|
69
|
-
end
|
70
|
-
unless flag.key?(:id)
|
71
|
-
raise ArgumentError, 'Not all required keys available!'
|
72
|
-
end
|
73
|
-
flag.each do |k, v|
|
74
|
-
if %i[id reason].include?(k)
|
75
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
76
|
-
raise InvalidIDError, "ID out of range: #{v}"
|
77
|
-
end
|
78
|
-
instance_variable_set("@#{k}".to_sym, v)
|
79
|
-
elsif k == :created_at
|
80
|
-
@created_at = Time.at(v)
|
81
|
-
elsif k == :post_id
|
82
|
-
@post = E621::Post.new(id: v)
|
83
|
-
elsif k == :user_id
|
84
|
-
@user = E621::User.new(id: v)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
# @author Maxine Michalski
|
90
|
-
#
|
91
|
-
# Comparison method for flags
|
92
|
-
#
|
93
|
-
# @example Compare two notes, that are unequal
|
94
|
-
# Note.new(id: 1) == Note.new(id: 2) #=> false
|
95
|
-
# @return [TrueClass, FalseClass]
|
96
|
-
def ==(other)
|
97
|
-
other.is_a?(E621::Post::Flag) && @id == other.id
|
98
|
-
end
|
99
|
-
|
100
|
-
# @author Maxine Michalski
|
101
|
-
#
|
102
|
-
# Turn object into a hash representation of itself
|
103
|
-
#
|
104
|
-
# @example Turn a Flag into a Hash
|
105
|
-
# Note.new(id: 1).to_hash #=> { id: 1 }
|
106
|
-
# @return [Hash]
|
107
|
-
def to_hash
|
108
|
-
hash = {}
|
109
|
-
instance_variables.each do |i|
|
110
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
111
|
-
end
|
112
|
-
hash
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,174 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
class Post
|
21
|
-
# This class holds note information. Notes are additional information on
|
22
|
-
# posts.
|
23
|
-
#
|
24
|
-
# @author Maxine Michalski
|
25
|
-
# @api public
|
26
|
-
# @since 2.0.0
|
27
|
-
class Note
|
28
|
-
# Note ID
|
29
|
-
# @example Get note ID
|
30
|
-
# note.id #=> Integer
|
31
|
-
# @return [Integer] id for this note
|
32
|
-
attr_reader :id
|
33
|
-
|
34
|
-
# Note creation time
|
35
|
-
# @example Get time note was created
|
36
|
-
# note.created_at #=> Time
|
37
|
-
# @return [Time] time of creation
|
38
|
-
attr_reader :created_at
|
39
|
-
|
40
|
-
# Time note was last updated
|
41
|
-
# @example Get time note was last updated
|
42
|
-
# @return [Time] time of last update
|
43
|
-
attr_reader :updated_at
|
44
|
-
|
45
|
-
# Note creator
|
46
|
-
# @example Get creator of note
|
47
|
-
# note.creator #=> E621::User
|
48
|
-
# @return [E621::User] user object of creator
|
49
|
-
attr_reader :creator
|
50
|
-
|
51
|
-
# X position of note
|
52
|
-
# @example Get x position of note
|
53
|
-
# note.x #=> Integer
|
54
|
-
# @return [Integer] position x value
|
55
|
-
attr_reader :x
|
56
|
-
|
57
|
-
# Y position of note
|
58
|
-
# @example Get y position of note
|
59
|
-
# note.y #=> Integer
|
60
|
-
# @return [Integer] position y value
|
61
|
-
attr_reader :y
|
62
|
-
|
63
|
-
# Convenience method for getting the entire point
|
64
|
-
# @example Get position of note as a point
|
65
|
-
# note.point #=> [x, y]
|
66
|
-
# @return [Array<Integer>] combined position (x, y)
|
67
|
-
attr_reader :point
|
68
|
-
|
69
|
-
# Width of note
|
70
|
-
# @example Get width of note
|
71
|
-
# note.width #=> Integer
|
72
|
-
# @return [Integer] width of object
|
73
|
-
attr_reader :width
|
74
|
-
|
75
|
-
# Height of note
|
76
|
-
# @example Get height of note
|
77
|
-
# note.height #=> Integer
|
78
|
-
# @return [Integer] height of object
|
79
|
-
attr_reader :height
|
80
|
-
|
81
|
-
# Describe note position and size via a rectangular
|
82
|
-
# @example Get note position and size
|
83
|
-
# note.rect #=> [x, y, width, height]
|
84
|
-
# @return [Array<Integer>] combined rectangular (x, y, width, height)
|
85
|
-
attr_reader :rect
|
86
|
-
|
87
|
-
# Post this note belongs to
|
88
|
-
# @example Get post this note belongs to
|
89
|
-
# note.post #=> E621::Post
|
90
|
-
# @return [E621::Post] post this note belongs to
|
91
|
-
attr_reader :post
|
92
|
-
|
93
|
-
# Text of note
|
94
|
-
# @example Get text of this note
|
95
|
-
# note.body #=> String
|
96
|
-
# @return [String] text content of note
|
97
|
-
attr_reader :body
|
98
|
-
|
99
|
-
# Version of note
|
100
|
-
# @example Get version of note
|
101
|
-
# note.version => Integer
|
102
|
-
# @return [Integer] version of this note
|
103
|
-
attr_reader :version
|
104
|
-
|
105
|
-
# @author Maxine Michalski
|
106
|
-
#
|
107
|
-
# Initializer for Note
|
108
|
-
#
|
109
|
-
# @param note [Hash] note information in hash form
|
110
|
-
# @example Get new note instance
|
111
|
-
# E621::Post::Note.new(id: 1) #=> E621::Post::Note instance
|
112
|
-
# @return the object
|
113
|
-
def initialize(note)
|
114
|
-
unless note.is_a?(Hash)
|
115
|
-
raise ArgumentError, "#{note.class} is not a Hash"
|
116
|
-
end
|
117
|
-
raise ArgumentError, 'An id is required' if note[:id].nil?
|
118
|
-
note.each do |k, v|
|
119
|
-
if %i[id x y width height is_active version body].include?(k)
|
120
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
121
|
-
raise InvalidIDError, "Invalid id: #{v}"
|
122
|
-
end
|
123
|
-
instance_variable_set("@#{k}".to_sym, v)
|
124
|
-
elsif %i[created_at updated_at].include?(k)
|
125
|
-
instance_variable_set("@#{k}".to_sym, Time.at(v[:s]))
|
126
|
-
elsif k == :post_id
|
127
|
-
@post = E621::Post.new(id: v)
|
128
|
-
elsif k == :creator_id
|
129
|
-
@creator = E621::User.new(id: v)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
@point = [@x, @y]
|
133
|
-
@rect = [@x, @y, @width, @height]
|
134
|
-
end
|
135
|
-
|
136
|
-
# @author Maxine Michalski
|
137
|
-
#
|
138
|
-
# Determine if note is active or not
|
139
|
-
# @example Is note active?
|
140
|
-
# note.active? #=> true or false
|
141
|
-
# @return [TrueClass|FalseClass] active state of note
|
142
|
-
def active?
|
143
|
-
return false if @is_active.nil?
|
144
|
-
@is_active
|
145
|
-
end
|
146
|
-
|
147
|
-
# @author Maxine Michalski
|
148
|
-
#
|
149
|
-
# Comparison method for Notes, to give a more meaningful comparison
|
150
|
-
# @param other [Object] object that should be compared
|
151
|
-
# @example Compare two notes, that are unequal
|
152
|
-
# Note.new(id: 1) == Note.new(id: 2) #=> false
|
153
|
-
# @return [TrueClass, FalseClass]
|
154
|
-
def ==(other)
|
155
|
-
other.is_a?(Note) && @id == other.id && @version == other.version
|
156
|
-
end
|
157
|
-
|
158
|
-
# @author Maxine Michalski
|
159
|
-
#
|
160
|
-
# Turn object into a hash representation of itself
|
161
|
-
#
|
162
|
-
# @example Turn a Note into a Hash
|
163
|
-
# Note.new(id: 1).to_hash #=> { id: 1 }
|
164
|
-
# @return [Hash]
|
165
|
-
def to_hash
|
166
|
-
hash = {}
|
167
|
-
instance_variables.each do |i|
|
168
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
169
|
-
end
|
170
|
-
hash
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2014-2018, 2020 Maxine Michalski <maxine@furfind.net>
|
4
|
-
#
|
5
|
-
# This file is part of rubyhexagon.
|
6
|
-
#
|
7
|
-
# rubyhexagon is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# rubyhexagon is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU General Public License for more details.
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with rubyhexagon. If not, see <http://www.gnu.org/licenses/>.
|
18
|
-
|
19
|
-
module Rubyhexagon
|
20
|
-
class Post
|
21
|
-
# Class to represent post tag_items
|
22
|
-
#
|
23
|
-
# @author Maxine Michalski
|
24
|
-
# @api public
|
25
|
-
# @since 2.0.0
|
26
|
-
class TagItem
|
27
|
-
# Tag item ID
|
28
|
-
# @example Get tag item ID
|
29
|
-
# tag_item.id #=> Integer
|
30
|
-
# @return [Integer] id of tag item
|
31
|
-
attr_reader :id
|
32
|
-
|
33
|
-
# Creation time of tag item
|
34
|
-
# @example Get creation time of tag item
|
35
|
-
# tag_item.created_at #=> Time
|
36
|
-
# @return [Time] creation time of tag item
|
37
|
-
attr_reader :created_at
|
38
|
-
|
39
|
-
# Post for this tag item
|
40
|
-
# @example Get post this tag item belongs to
|
41
|
-
# tag_item.post #=> E621::Post
|
42
|
-
# @return [E621::Post] post for this tag item
|
43
|
-
attr_reader :post
|
44
|
-
|
45
|
-
# Changed tags inside tag item
|
46
|
-
# @example Get changed tags of tag item
|
47
|
-
# tag_item.tags #=> Array<E621::Tag>
|
48
|
-
# @return [Array<E621::Tags>] tags this tag item contains
|
49
|
-
attr_reader :tags
|
50
|
-
|
51
|
-
# New sources for post in tag item
|
52
|
-
# @example Get sources of tag item
|
53
|
-
# tag_item.sources #=> Array<String>
|
54
|
-
# @return [Array<String>] changed sources
|
55
|
-
attr_reader :sources
|
56
|
-
|
57
|
-
# @author Maxine Michalski
|
58
|
-
#
|
59
|
-
# Initializer for tag change items
|
60
|
-
#
|
61
|
-
# @param tag_item [Hash] tag item data
|
62
|
-
#
|
63
|
-
# @example Get instance of flag
|
64
|
-
# E621::Post::TagItem.new(id: 1, created_at: 1
|
65
|
-
# post_id: 1, tags: '', source: '') #=> E621::Post::TagItem instance
|
66
|
-
# @return the object
|
67
|
-
def initialize(tag_item)
|
68
|
-
unless tag_item.is_a?(Hash)
|
69
|
-
raise ArgumentError, "#{tag_item.class} is not a Hash"
|
70
|
-
end
|
71
|
-
unless (miss = %i[id created_at post_id tags source] -
|
72
|
-
tag_item.keys).empty?
|
73
|
-
raise ArgumentError, 'Not all required keys available! '\
|
74
|
-
"Missing: #{miss}"
|
75
|
-
end
|
76
|
-
id = tag_item[:id]
|
77
|
-
unless id.is_a?(Integer) && id.positive?
|
78
|
-
raise InvalidIDError, "ID out of range: #{id}"
|
79
|
-
end
|
80
|
-
@id = id
|
81
|
-
@created_at = Time.at(tag_item[:created_at])
|
82
|
-
@post = E621::Post.new(id: tag_item[:post_id])
|
83
|
-
@tags = tag_item[:tags].split(' ').map { |t| E621::Tag.new(name: t) }
|
84
|
-
@sources = tag_item[:source].split($INPUT_RECORD_SEPARATOR)
|
85
|
-
end
|
86
|
-
|
87
|
-
# @author Maxine Michalski
|
88
|
-
#
|
89
|
-
# Comparison method for tag change items
|
90
|
-
#
|
91
|
-
# @example Compare two notes, that are unequal
|
92
|
-
# Note.new(id: 1) == Note.new(id: 2) #=> false
|
93
|
-
# @return [TrueClass, FalseClass]
|
94
|
-
def ==(other)
|
95
|
-
other.is_a?(E621::Post::TagItem) && @id == other.id
|
96
|
-
end
|
97
|
-
|
98
|
-
# @author Maxine Michalski
|
99
|
-
#
|
100
|
-
# Turn object into a hash representation of itself
|
101
|
-
#
|
102
|
-
# @example Turn a TagItem into a Hash
|
103
|
-
# Note.new(id: 1).to_hash #=> { id: 1 }
|
104
|
-
# @return [Hash]
|
105
|
-
def to_hash
|
106
|
-
hash = {}
|
107
|
-
instance_variables.each do |i|
|
108
|
-
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
109
|
-
end
|
110
|
-
hash
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|