rubyhexagon 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubyhexagon.rb +3 -3
- data/lib/rubyhexagon/api.rb +1 -1
- data/lib/rubyhexagon/api/artist.rb +10 -0
- data/lib/rubyhexagon/api/pool.rb +29 -0
- data/lib/rubyhexagon/api/post.rb +63 -3
- data/lib/rubyhexagon/api/post/flag.rb +9 -0
- data/lib/rubyhexagon/api/post/note.rb +77 -0
- data/lib/rubyhexagon/api/post/tag_item.rb +9 -0
- data/lib/rubyhexagon/api/tag.rb +10 -4
- data/lib/rubyhexagon/api/tag/alias.rb +5 -0
- data/lib/rubyhexagon/api/tag/implication.rb +5 -0
- data/lib/rubyhexagon/api/user.rb +16 -1
- data/lib/rubyhexagon/artist.rb +66 -6
- data/lib/rubyhexagon/error.rb +0 -19
- data/lib/rubyhexagon/pool.rb +54 -8
- data/lib/rubyhexagon/post.rb +145 -25
- data/lib/rubyhexagon/post/flag.rb +38 -0
- data/lib/rubyhexagon/post/image.rb +25 -3
- data/lib/rubyhexagon/post/note.rb +174 -0
- data/lib/rubyhexagon/post/tag_item.rb +45 -5
- data/lib/rubyhexagon/tag.rb +37 -4
- data/lib/rubyhexagon/tag/alias.rb +35 -6
- data/lib/rubyhexagon/tag/implication.rb +35 -5
- data/lib/rubyhexagon/tag/type.rb +20 -5
- data/lib/rubyhexagon/user.rb +40 -3
- data/lib/rubyhexagon/user/level.rb +13 -3
- metadata +4 -4
- data/lib/rubyhexagon/api/note.rb +0 -50
- data/lib/rubyhexagon/note.rb +0 -112
@@ -21,20 +21,30 @@ module Rubyhexagon
|
|
21
21
|
# Class to hold alias information.
|
22
22
|
#
|
23
23
|
# @author Maxine Michalski
|
24
|
+
# @api public
|
24
25
|
# @since 2.0.0
|
25
26
|
class Alias
|
27
|
+
# Alias ID
|
28
|
+
# @example Get alias ID
|
29
|
+
# alias.id #=> Integer
|
26
30
|
# @return [Integer] id of alias
|
27
31
|
attr_reader :id
|
28
32
|
|
33
|
+
# Alias name
|
34
|
+
# @example Get alias name
|
35
|
+
# alias.name #=> String
|
29
36
|
# @return [String] name of alias
|
30
37
|
attr_reader :name
|
31
38
|
|
39
|
+
# Tag this alias is for
|
40
|
+
# @example Get aliased tag
|
41
|
+
# alias.alias_to #=> E621::Tag
|
32
42
|
# @return [E621::Tag] tag this alias is aliased to
|
33
43
|
attr_reader :alias_to
|
34
44
|
|
35
45
|
# @author Maxine Michalski
|
36
46
|
#
|
37
|
-
# Initializer for Alias
|
47
|
+
# Initializer for Alias
|
38
48
|
#
|
39
49
|
# @raise InvalidIDError if alias ID is not valid
|
40
50
|
# @raise ArgumentError hash not valid
|
@@ -44,7 +54,9 @@ module Rubyhexagon
|
|
44
54
|
# @option ali [String] :name alias for tag
|
45
55
|
# @option ali [Integer] :alias_id ID of tag to alias
|
46
56
|
# @option ali [TrueClass|FalseClass] :pending statud
|
47
|
-
#
|
57
|
+
# @example Get alias isntance
|
58
|
+
# E621::Tag::Alias.new(id: 1, name: 'test', alias_id: 1,
|
59
|
+
# pending: false) #=> E621::Tag::Alias instance
|
48
60
|
# @return the object
|
49
61
|
def initialize(ali)
|
50
62
|
raise ArgumentError, "#{ali.class} is not a Hash" unless ali.is_a?(Hash)
|
@@ -66,8 +78,9 @@ module Rubyhexagon
|
|
66
78
|
|
67
79
|
# @author Maxine Michalski
|
68
80
|
#
|
69
|
-
# Comparison method for Types, to give a more meaningful comparison
|
70
|
-
#
|
81
|
+
# Comparison method for Types, to give a more meaningful comparison
|
82
|
+
# @example Compare two tags, that are unequal
|
83
|
+
# Tag.new(id: 1) == Tag.new(id: 2) #=> false
|
71
84
|
# @return [TrueClass, FalseClass]
|
72
85
|
def ==(other)
|
73
86
|
other.is_a?(Alias) && @id == other.id
|
@@ -75,13 +88,29 @@ module Rubyhexagon
|
|
75
88
|
|
76
89
|
# @author Maxine Michalski
|
77
90
|
#
|
78
|
-
# Check if this alias is pending confirmation
|
79
|
-
#
|
91
|
+
# Check if this alias is pending confirmation
|
92
|
+
# @example Is alias pending?
|
93
|
+
# alias.pending? #=> true or false
|
80
94
|
# @return [TrueClass] tag alias is pending
|
81
95
|
# @return [FalseClass] tag alias is not pending
|
82
96
|
def pending?
|
83
97
|
@pending
|
84
98
|
end
|
99
|
+
|
100
|
+
# @author Maxine Michalski
|
101
|
+
#
|
102
|
+
# Turn object into a hash representation of itself
|
103
|
+
#
|
104
|
+
# @example Turn an Alias into a Hash
|
105
|
+
# Tag.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
|
85
114
|
end
|
86
115
|
end
|
87
116
|
end
|
@@ -21,20 +21,30 @@ module Rubyhexagon
|
|
21
21
|
# Class to hold implication information.
|
22
22
|
#
|
23
23
|
# @author Maxine Michalski
|
24
|
+
# @api public
|
24
25
|
# @since 2.0.0
|
25
26
|
class Implication
|
27
|
+
# Implication ID
|
28
|
+
# @example Get implication ID
|
29
|
+
# implication.id #=> Integer
|
26
30
|
# @return [Integer] id of implication
|
27
31
|
attr_reader :id
|
28
32
|
|
33
|
+
# Tag that implies another tag
|
34
|
+
# @example Get implying tag
|
35
|
+
# implication.tag #=> E621::Tag
|
29
36
|
# @return [E621::Tag] implying tag
|
30
37
|
attr_reader :tag
|
31
38
|
|
39
|
+
# Tag that is implied
|
40
|
+
# @example Get implied tag
|
41
|
+
# implication.implied #=> E621::Tag
|
32
42
|
# @return [E621::Tag] implied tag
|
33
43
|
attr_reader :implies
|
34
44
|
|
35
45
|
# @author Maxine Michalski
|
36
46
|
#
|
37
|
-
# Initializer for Implication
|
47
|
+
# Initializer for Implication
|
38
48
|
#
|
39
49
|
# @raise InvalidIDError if implication ID is not valid
|
40
50
|
# @raise ArgumentError hash not valid
|
@@ -44,7 +54,9 @@ module Rubyhexagon
|
|
44
54
|
# @option imply [Integer] :consequent_id implying tag ID
|
45
55
|
# @option imply [Integer] :predicate_id implied tag ID
|
46
56
|
# @option imply [TrueClass|FalseClass] :pending statud
|
47
|
-
#
|
57
|
+
# @example Get new implication instance
|
58
|
+
# E621::Tag::Implication.new(id: 1, consequent_id: 1, predicate_id: 2,
|
59
|
+
# pending: false) #=> E621::Tag::Implication
|
48
60
|
# @return the object
|
49
61
|
def initialize(imply)
|
50
62
|
unless imply.is_a?(Hash)
|
@@ -70,8 +82,9 @@ module Rubyhexagon
|
|
70
82
|
|
71
83
|
# @author Maxine Michalski
|
72
84
|
#
|
73
|
-
# Comparison method for Types, to give a more meaningful comparison
|
74
|
-
#
|
85
|
+
# Comparison method for Types, to give a more meaningful comparison
|
86
|
+
# @example Compare two tags, that are unequal
|
87
|
+
# Tag.new(id: 1) == Tag.new(id: 2) #=> false
|
75
88
|
# @return [TrueClass, FalseClass]
|
76
89
|
def ==(other)
|
77
90
|
other.is_a?(Implication) && @id == other.id
|
@@ -79,13 +92,30 @@ module Rubyhexagon
|
|
79
92
|
|
80
93
|
# @author Maxine Michalski
|
81
94
|
#
|
82
|
-
# Check if this implication is pending confirmation
|
95
|
+
# Check if this implication is pending confirmation
|
83
96
|
#
|
97
|
+
# @example Is implication pending?
|
98
|
+
# implication.pending? #=> true or false
|
84
99
|
# @return [TrueClass] tag implication is pending
|
85
100
|
# @return [FalseClass] tag implication is not pending
|
86
101
|
def pending?
|
87
102
|
@pending
|
88
103
|
end
|
104
|
+
|
105
|
+
# @author Maxine Michalski
|
106
|
+
#
|
107
|
+
# Turn object into a hash representation of itself
|
108
|
+
#
|
109
|
+
# @example Turn a User into a Hash
|
110
|
+
# Tag.new(id: 1).to_hash #=> { id: 1 }
|
111
|
+
# @return [Hash]
|
112
|
+
def to_hash
|
113
|
+
hash = {}
|
114
|
+
instance_variables.each do |i|
|
115
|
+
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
116
|
+
end
|
117
|
+
hash
|
118
|
+
end
|
89
119
|
end
|
90
120
|
end
|
91
121
|
end
|
data/lib/rubyhexagon/tag/type.rb
CHANGED
@@ -24,17 +24,17 @@ module Rubyhexagon
|
|
24
24
|
# @author Maxine Michalski
|
25
25
|
# @since 1.0.0
|
26
26
|
class Type
|
27
|
+
# Type ID
|
27
28
|
# @return [Integer] id of type
|
28
29
|
attr_reader :id
|
29
30
|
|
31
|
+
# Type name
|
30
32
|
# @return [String] name of type
|
31
33
|
attr_reader :name
|
32
34
|
|
33
35
|
# @author Maxine Michalski
|
34
36
|
#
|
35
|
-
# Initializer for Type
|
36
|
-
#
|
37
|
-
# @raise ArgumentError if type ID is not valid
|
37
|
+
# Initializer for Type
|
38
38
|
#
|
39
39
|
# @param type [Hash] type data, fetched from e621
|
40
40
|
# @option type [Integer] :id Type ID (can be one of 0, 1, 3, 4 or 5
|
@@ -57,7 +57,7 @@ module Rubyhexagon
|
|
57
57
|
|
58
58
|
# @author Maxine Michalski
|
59
59
|
#
|
60
|
-
# Comparison method for Types, to give a more meaningful comparison
|
60
|
+
# Comparison method for Types, to give a more meaningful comparison
|
61
61
|
#
|
62
62
|
# @return [TrueClass, FalseClass]
|
63
63
|
def ==(other)
|
@@ -67,13 +67,28 @@ module Rubyhexagon
|
|
67
67
|
|
68
68
|
# @author Maxine Michalski
|
69
69
|
#
|
70
|
-
# Check if this type is locked for the tag who has it assigned
|
70
|
+
# Check if this type is locked for the tag who has it assigned
|
71
71
|
#
|
72
72
|
# @return [TrueClass] tag type is locked
|
73
73
|
# @return [FalseClass] tag type is not locked
|
74
74
|
def locked?
|
75
75
|
@locked
|
76
76
|
end
|
77
|
+
|
78
|
+
# @author Maxine Michalski
|
79
|
+
#
|
80
|
+
# Turn object into a hash representation of itself
|
81
|
+
#
|
82
|
+
# @example Turn a User into a Hash
|
83
|
+
# Tag.new(id: 1).to_hash #=> { id: 1 }
|
84
|
+
# @return [Hash]
|
85
|
+
def to_hash
|
86
|
+
hash = {}
|
87
|
+
instance_variables.each do |i|
|
88
|
+
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
89
|
+
end
|
90
|
+
hash
|
91
|
+
end
|
77
92
|
end
|
78
93
|
end
|
79
94
|
end
|
data/lib/rubyhexagon/user.rb
CHANGED
@@ -22,30 +22,51 @@ module Rubyhexagon
|
|
22
22
|
# Class to hold user information for users on e621.
|
23
23
|
#
|
24
24
|
# @author Maxine Michalski
|
25
|
+
# @api public
|
25
26
|
# @since 1.0.0
|
26
27
|
class User
|
28
|
+
# User ID
|
29
|
+
# @example Get ID from user
|
30
|
+
# user.id #=> Integer
|
27
31
|
# @return [Integer] id of user
|
28
32
|
attr_reader :id
|
29
33
|
|
34
|
+
# User name
|
35
|
+
# @example Get name from user
|
36
|
+
# user.name #=> String
|
30
37
|
# @return [String] name of user
|
31
38
|
attr_reader :name
|
32
39
|
|
33
|
-
#
|
40
|
+
# User access level
|
41
|
+
# @example Get user access level
|
42
|
+
# user.level #=> E621::User::Level
|
43
|
+
# @return [E621::User::Level] level of access, this user holds
|
34
44
|
attr_reader :level
|
35
45
|
|
46
|
+
# Time user was created
|
47
|
+
# @example Get user creation time
|
48
|
+
# user.created_at #=> Time
|
36
49
|
# @return [Time] registration time of this user
|
37
50
|
attr_reader :created_at
|
38
51
|
|
52
|
+
# Avatar post that user chosen
|
53
|
+
# @example Get user avatar post
|
54
|
+
# user.avatar #=> E621::Post
|
39
55
|
# @return [E621::Post] avatar set by user
|
40
56
|
attr_reader :avatar
|
41
57
|
|
58
|
+
# Artists tags, that belong to user
|
59
|
+
# @example Get artist tags
|
60
|
+
# user.artist_tags #=> Array<E621::Tag>
|
42
61
|
# @return [Array<E621::Tag>] an array of artist tags, associated with user
|
43
62
|
attr_reader :artist_tags
|
44
63
|
|
45
64
|
# @author Maxine Michalski
|
46
65
|
#
|
47
|
-
# Initializer for User
|
66
|
+
# Initializer for User
|
48
67
|
#
|
68
|
+
# @example Get a new user instance
|
69
|
+
# User.new(:id) #=> E621::User instance
|
49
70
|
# @param user [Hash] user data, fetched from e621
|
50
71
|
#
|
51
72
|
# @return the object
|
@@ -70,8 +91,24 @@ module Rubyhexagon
|
|
70
91
|
|
71
92
|
# @author Maxine Michalski
|
72
93
|
#
|
73
|
-
#
|
94
|
+
# Turn object into a hash representation of itself
|
74
95
|
#
|
96
|
+
# @example Turn a User into a Hash
|
97
|
+
# User.new(id: 1).to_hash #=> { id: 1 }
|
98
|
+
# @return [Hash]
|
99
|
+
def to_hash
|
100
|
+
hash = {}
|
101
|
+
instance_variables.each do |i|
|
102
|
+
hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
|
103
|
+
end
|
104
|
+
hash
|
105
|
+
end
|
106
|
+
|
107
|
+
# @author Maxine Michalski
|
108
|
+
#
|
109
|
+
# Comparison method for User objects
|
110
|
+
# @example Check two different users
|
111
|
+
# User.new(id: 1) == User.new(id: 2) #=> false
|
75
112
|
# @return [TrueClass, FalseClass]
|
76
113
|
def ==(other)
|
77
114
|
other.is_a?(User) && @id == other.id
|
@@ -24,16 +24,17 @@ module Rubyhexagon
|
|
24
24
|
# @author Maxine Michalski
|
25
25
|
# @since 1.0.0
|
26
26
|
class Level
|
27
|
+
# User level ID
|
27
28
|
# @return [Integer] id of level
|
28
29
|
attr_reader :id
|
29
30
|
|
31
|
+
# User level name
|
30
32
|
# @return [String] name of level
|
31
33
|
attr_reader :name
|
32
34
|
|
33
35
|
# @author Maxine Michalski
|
34
36
|
#
|
35
|
-
# Initializer for Level a user can have
|
36
|
-
# like interface to it.
|
37
|
+
# Initializer for Level a user can have
|
37
38
|
#
|
38
39
|
# @param level [Hash] level a user can have.
|
39
40
|
#
|
@@ -63,7 +64,16 @@ module Rubyhexagon
|
|
63
64
|
|
64
65
|
# @author Maxine Michalski
|
65
66
|
#
|
66
|
-
#
|
67
|
+
# Turn object into a hash representation of itself
|
68
|
+
#
|
69
|
+
# @return [Hash]
|
70
|
+
def to_hash
|
71
|
+
{ id: @id, name: @name }
|
72
|
+
end
|
73
|
+
|
74
|
+
# @author Maxine Michalski
|
75
|
+
#
|
76
|
+
# Test function for level names
|
67
77
|
#
|
68
78
|
# @return [TrueClass|FalseClass]
|
69
79
|
def test
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyhexagon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxine Michalski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -33,10 +33,10 @@ files:
|
|
33
33
|
- lib/rubyhexagon.rb
|
34
34
|
- lib/rubyhexagon/api.rb
|
35
35
|
- lib/rubyhexagon/api/artist.rb
|
36
|
-
- lib/rubyhexagon/api/note.rb
|
37
36
|
- lib/rubyhexagon/api/pool.rb
|
38
37
|
- lib/rubyhexagon/api/post.rb
|
39
38
|
- lib/rubyhexagon/api/post/flag.rb
|
39
|
+
- lib/rubyhexagon/api/post/note.rb
|
40
40
|
- lib/rubyhexagon/api/post/tag_item.rb
|
41
41
|
- lib/rubyhexagon/api/tag.rb
|
42
42
|
- lib/rubyhexagon/api/tag/alias.rb
|
@@ -44,11 +44,11 @@ files:
|
|
44
44
|
- lib/rubyhexagon/api/user.rb
|
45
45
|
- lib/rubyhexagon/artist.rb
|
46
46
|
- lib/rubyhexagon/error.rb
|
47
|
-
- lib/rubyhexagon/note.rb
|
48
47
|
- lib/rubyhexagon/pool.rb
|
49
48
|
- lib/rubyhexagon/post.rb
|
50
49
|
- lib/rubyhexagon/post/flag.rb
|
51
50
|
- lib/rubyhexagon/post/image.rb
|
51
|
+
- lib/rubyhexagon/post/note.rb
|
52
52
|
- lib/rubyhexagon/post/tag_item.rb
|
53
53
|
- lib/rubyhexagon/search/posts.rb
|
54
54
|
- lib/rubyhexagon/tag.rb
|
data/lib/rubyhexagon/api/note.rb
DELETED
@@ -1,50 +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
|
-
# A class to interact with the e621 web interface.
|
21
|
-
#
|
22
|
-
# @author Maxine Michalski
|
23
|
-
# @since 2.0.0
|
24
|
-
class Note
|
25
|
-
def self.list(post)
|
26
|
-
unless post.is_a?(Hash) || post.is_a?(E621::Post)
|
27
|
-
raise ArgumentError, 'A Hash or Post object is required'
|
28
|
-
end
|
29
|
-
post.store(:post_id, post.delete(:id)) if post.is_a?(Hash)
|
30
|
-
post = { post_id: post.id } if post.is_a?(E621::Post)
|
31
|
-
E621::API.fetch(:note, :index, post).map do |note|
|
32
|
-
new(note)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.search(query)
|
37
|
-
raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
|
38
|
-
E621::API.fetch(:note, :search, query).map do |note|
|
39
|
-
new(note)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.history(query)
|
44
|
-
raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash)
|
45
|
-
E621::API.fetch(:note, :history, query).map do |note|
|
46
|
-
new(note)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/lib/rubyhexagon/note.rb
DELETED
@@ -1,112 +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 note information. Notes are additional information on
|
21
|
-
# posts.
|
22
|
-
#
|
23
|
-
# @author Maxine Michalski
|
24
|
-
# @since 2.0.0
|
25
|
-
class Note
|
26
|
-
# @return [Integer] id for this note
|
27
|
-
attr_reader :id
|
28
|
-
|
29
|
-
# @return [Time] time of creation
|
30
|
-
attr_reader :created_at
|
31
|
-
|
32
|
-
# @return [Time] time of last update
|
33
|
-
attr_reader :updated_at
|
34
|
-
|
35
|
-
# @return [E621::User] user object of creator
|
36
|
-
attr_reader :creator
|
37
|
-
|
38
|
-
# @return [Integer] position x value
|
39
|
-
attr_reader :x
|
40
|
-
|
41
|
-
# @return [Integer] position y value
|
42
|
-
attr_reader :y
|
43
|
-
|
44
|
-
# @return [Array<Integer>] combined position (x, y)
|
45
|
-
attr_reader :point
|
46
|
-
|
47
|
-
# @return [Integer] width of object
|
48
|
-
attr_reader :width
|
49
|
-
|
50
|
-
# @return [Integer] height of object
|
51
|
-
attr_reader :height
|
52
|
-
|
53
|
-
# @return [Array<Integer>] combined rectangular (x, y, width, height)
|
54
|
-
attr_reader :rect
|
55
|
-
|
56
|
-
# @return [E621::Post] post this note belongs to
|
57
|
-
attr_reader :post
|
58
|
-
|
59
|
-
# @return [String] text content of note
|
60
|
-
attr_reader :body
|
61
|
-
|
62
|
-
# @return [Integer] version of this note
|
63
|
-
attr_reader :version
|
64
|
-
|
65
|
-
# @author Maxine Michalski
|
66
|
-
#
|
67
|
-
# Initializer for Note.
|
68
|
-
#
|
69
|
-
# @param note [Hash] note information in hash form
|
70
|
-
#
|
71
|
-
# @return the object
|
72
|
-
def initialize(note)
|
73
|
-
raise ArgumentError, "#{note.class} is not a Hash" unless note.is_a?(Hash)
|
74
|
-
raise ArgumentError, 'An id is required' if note[:id].nil?
|
75
|
-
note.each do |k, v|
|
76
|
-
if %i[id x y width height is_active version body].include?(k)
|
77
|
-
if k == :id && !(v.is_a?(Integer) && v.positive?)
|
78
|
-
raise InvalidIDError, "Invalid id: #{v}"
|
79
|
-
end
|
80
|
-
instance_variable_set("@#{k}".to_sym, v)
|
81
|
-
elsif %i[created_at updated_at].include?(k)
|
82
|
-
instance_variable_set("@#{k}".to_sym, Time.at(v[:s]))
|
83
|
-
elsif k == :post_id
|
84
|
-
@post = E621::Post.new(id: v)
|
85
|
-
elsif k == :creator_id
|
86
|
-
@creator = E621::User.new(id: v)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
@point = [@x, @y]
|
90
|
-
@rect = [@x, @y, @width, @height]
|
91
|
-
end
|
92
|
-
|
93
|
-
# @author Maxine Michalski
|
94
|
-
#
|
95
|
-
# Determine if note is active or not.
|
96
|
-
#
|
97
|
-
# @return [TrueClass|FalseClass] active state of note
|
98
|
-
def active?
|
99
|
-
return false if @is_active.nil?
|
100
|
-
@is_active
|
101
|
-
end
|
102
|
-
|
103
|
-
# @author Maxine Michalski
|
104
|
-
#
|
105
|
-
# Comparison method for Notes, to give a more meaningful comparison.
|
106
|
-
#
|
107
|
-
# @return [TrueClass, FalseClass]
|
108
|
-
def ==(other)
|
109
|
-
other.is_a?(Note) && @id == other.id && @version == other.version
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|