rubyhexagon 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,17 +21,36 @@ module Rubyhexagon
21
21
  # Class to represent post flags
22
22
  #
23
23
  # @author Maxine Michalski
24
+ # @api public
24
25
  # @since 2.0.0
25
26
  class Flag
27
+ # Flag ID
28
+ # @example Get flag ID
29
+ # flag.id #=> Integer
26
30
  # @return [Integer] id of flag
27
31
  attr_reader :id
28
32
 
33
+ # Creation time of flag
34
+ # @example Get flag creation time
35
+ # flag.created_at #=> Time
29
36
  # @return [Time] creation time of flag
30
37
  attr_reader :created_at
38
+
39
+ # Flag post
40
+ # @example Get post that this flag references
41
+ # flag.post #=> E621::Post
31
42
  # @return [621::Post] Post this flag is addressed to
32
43
  attr_reader :post
44
+
45
+ # Flagging reason
46
+ # @example Get reason for flagging
47
+ # flag.reason #=> String
33
48
  # @return [String] reason for flag
34
49
  attr_reader :reason
50
+
51
+ # User that initiated flagging
52
+ # @example Get user that flagged post
53
+ # flag.user #=> E621::User
35
54
  # @return [E621::User] User who flagged
36
55
  attr_reader :user
37
56
 
@@ -41,6 +60,8 @@ module Rubyhexagon
41
60
  #
42
61
  # @param flag [Hash] flag data
43
62
  #
63
+ # @example Get instance of flag
64
+ # E621::Post::Flag.new(id: 1) #=> E621::Post::Flag instance
44
65
  # @return the object
45
66
  def initialize(flag)
46
67
  unless flag.is_a?(Hash)
@@ -69,10 +90,27 @@ module Rubyhexagon
69
90
  #
70
91
  # Comparison method for flags
71
92
  #
93
+ # @example Compare two notes, that are unequal
94
+ # Note.new(id: 1) == Note.new(id: 2) #=> false
72
95
  # @return [TrueClass, FalseClass]
73
96
  def ==(other)
74
97
  other.is_a?(E621::Post::Flag) && @id == other.id
75
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
76
114
  end
77
115
  end
78
116
  end
@@ -25,24 +25,29 @@ module Rubyhexagon
25
25
  # @author Maxine Michalski
26
26
  # @since 1.0.0
27
27
  class Image
28
+ # Image url
28
29
  # @return [URI] url of file
29
30
  attr_reader :url
30
31
 
32
+ # Image file extension
31
33
  # @return [String] extension of file
32
34
  attr_reader :ext
33
35
 
36
+ # Image width
34
37
  # @return [Integer] image/video width
35
38
  attr_reader :width
36
39
 
40
+ # Image height
37
41
  # @return [Integer] image/video height
38
42
  attr_reader :height
39
43
 
44
+ # Image file size
40
45
  # @return [Integer] file size in bytes
41
46
  attr_reader :size
42
47
 
43
48
  # @author Maxine Michalski
44
49
  #
45
- # Initializer for an Image.
50
+ # Initializer for an Image
46
51
  #
47
52
  # @param image [Hash] image information
48
53
  # @option image [String] :url URI location
@@ -71,7 +76,7 @@ module Rubyhexagon
71
76
 
72
77
  # @author Maxine Michalski
73
78
  #
74
- # A convenient function to return both width and height.
79
+ # A convenient function to return both width and height
75
80
  #
76
81
  # @return [Array<Integer>]
77
82
  def resolution
@@ -80,7 +85,7 @@ module Rubyhexagon
80
85
 
81
86
  # @author Maxine Michalski
82
87
  #
83
- # A convenient function to return the aspect ratio of a given image.
88
+ # A convenient function to return the aspect ratio of a given image
84
89
  #
85
90
  # @return [Float]
86
91
  def aspect_ratio
@@ -91,10 +96,27 @@ module Rubyhexagon
91
96
  #
92
97
  # Comparison method to comapre two Image objects (and sub class objects)
93
98
  #
99
+ # @example Compare two notes, that are unequal
100
+ # Note.new(id: 1) == Note.new(id: 2) #=> false
94
101
  # @return [TrueClass, FalseClass]
95
102
  def ==(other)
96
103
  other.is_a?(Image) && @url == other.url && @size == other.size
97
104
  end
105
+
106
+ # @author Maxine Michalski
107
+ #
108
+ # Turn object into a hash representation of itself
109
+ #
110
+ # @example Turn an Image into a Hash
111
+ # Note.new(id: 1).to_hash #=> { id: 1 }
112
+ # @return [Hash]
113
+ def to_hash
114
+ hash = {}
115
+ instance_variables.each do |i|
116
+ hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
117
+ end
118
+ hash
119
+ end
98
120
  end
99
121
 
100
122
  # class for samples, that is just a copy of Image
@@ -0,0 +1,174 @@
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
@@ -21,17 +21,37 @@ module Rubyhexagon
21
21
  # Class to represent post tag_items
22
22
  #
23
23
  # @author Maxine Michalski
24
+ # @api public
24
25
  # @since 2.0.0
25
26
  class TagItem
26
- # @return [Integer] id of post information
27
+ # Tag item ID
28
+ # @example Get tag item ID
29
+ # tag_item.id #=> Integer
30
+ # @return [Integer] id of tag item
27
31
  attr_reader :id
28
- # @return [Integer] id of post information
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
29
37
  attr_reader :created_at
30
- # @return [Integer] id of post information
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
31
43
  attr_reader :post
32
- # @return [Integer] id of post information
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
33
49
  attr_reader :tags
34
- # @return [Integer] id of post information
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
35
55
  attr_reader :sources
36
56
 
37
57
  # @author Maxine Michalski
@@ -40,6 +60,9 @@ module Rubyhexagon
40
60
  #
41
61
  # @param tag_item [Hash] tag item data
42
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
43
66
  # @return the object
44
67
  def initialize(tag_item)
45
68
  unless tag_item.is_a?(Hash)
@@ -65,10 +88,27 @@ module Rubyhexagon
65
88
  #
66
89
  # Comparison method for tag change items
67
90
  #
91
+ # @example Compare two notes, that are unequal
92
+ # Note.new(id: 1) == Note.new(id: 2) #=> false
68
93
  # @return [TrueClass, FalseClass]
69
94
  def ==(other)
70
95
  other.is_a?(E621::Post::TagItem) && @id == other.id
71
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
72
112
  end
73
113
  end
74
114
  end
@@ -20,27 +20,44 @@ module Rubyhexagon
20
20
  # Class to hold tag information.
21
21
  #
22
22
  # @author Maxine Michalski
23
+ # @api public
23
24
  # @since 1.0.0
24
25
  class Tag
26
+ # Tag ID
27
+ # @example Get Tag ID
28
+ # tag.id #=> Integer
25
29
  # @return [Integer] id of tag
26
30
  attr_reader :id
27
31
 
32
+ # Tag name
33
+ # @example Get tag name
34
+ # tag.name #=> String
28
35
  # @return [String] name of tag
29
36
  attr_reader :name
30
37
 
38
+ # Number of posts, this tag is assigned to
39
+ # @example Get post count of tag
40
+ # tag.count #=> Integer
31
41
  # @return [Integer] number of posts that have this tag assigned to them
32
42
  attr_reader :count
33
43
 
34
- # @return [Tag::Type] type of this tag
44
+ # Tag type
45
+ # @example Get tag type
46
+ # tag.type $=> E621::Tag::Type
47
+ # @return [E621::Tag::Type] type of this tag
35
48
  attr_reader :type
36
49
 
37
50
  # @author Maxine Michalski
38
51
  #
39
- # Initializer for Tag.
52
+ # Initializer for Tag
40
53
  #
41
54
  # @raise InvalidIDError|ArgumentError
42
55
  #
43
56
  # @param tag [Hash] tag data
57
+ # @example Get new tag instance by ID
58
+ # Tag.new(id: 1) #=> E621::Tag
59
+ # @example Get new tag instance by name
60
+ # E621::Tag.new(name: 'feline') #=> E621::Tag
44
61
  #
45
62
  # @return the object
46
63
  def initialize(tag)
@@ -63,10 +80,26 @@ module Rubyhexagon
63
80
 
64
81
  # @author Maxine Michalski
65
82
  #
66
- # Comparison operator for Tag, to override the default one.
83
+ # Turn object into a hash representation of itself
67
84
  #
68
- # @param other [Object] object that should be compared
85
+ # @example Turn a User into a Hash
86
+ # Tag.new(id: 1).to_hash #=> { id: 1 }
87
+ # @return [Hash]
88
+ def to_hash
89
+ hash = {}
90
+ instance_variables.each do |i|
91
+ hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i))
92
+ end
93
+ hash
94
+ end
95
+
96
+ # @author Maxine Michalski
97
+ #
98
+ # Comparison operator for Tag, to override the default one
69
99
  #
100
+ # @param other [Object] object that should be compared
101
+ # @example Compare two tags, that are unequal
102
+ # Tag.new(id: 1) == Tag.new(id: 2) #=> false
70
103
  # @return [TrueClass, FalseClass] test result of comparison
71
104
  def ==(other)
72
105
  return false unless other.is_a?(Tag)