Class: Rubyhexagon::Post::Flag
- Inherits:
-
Object
- Object
- Rubyhexagon::Post::Flag
- Defined in:
- lib/rubyhexagon/post/flag.rb,
lib/rubyhexagon/api/post/flag.rb
Overview
A class to interact with the e621 web interface.
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
Creation time of flag.
-
#id ⇒ Integer
readonly
Id of flag.
-
#post ⇒ 621::Post
readonly
Post this flag is addressed to.
-
#reason ⇒ String
readonly
Reason for flag.
-
#user ⇒ E621::User
readonly
User who flagged.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for flags.
-
#initialize(flag) ⇒ Object
constructor
Initializer for flags.
Constructor Details
#initialize(flag) ⇒ Object
Initializer for flags
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rubyhexagon/post/flag.rb', line 45 def initialize(flag) unless flag.is_a?(Hash) raise ArgumentError, "#{flag.class} is not a Hash" end unless flag.key?(:id) raise ArgumentError, 'Not all required keys available!' end flag.each do |k, v| if %i[id reason].include?(k) if k == :id && !(v.is_a?(Integer) && v.positive?) raise InvalidIDError, "ID out of range: #{v}" end instance_variable_set("@#{k}".to_sym, v) elsif k == :created_at @created_at = Time.at(v) elsif k == :post_id @post = E621::Post.new(id: v) elsif k == :user_id @user = E621::User.new(id: v) end end end |
Instance Attribute Details
#created_at ⇒ Time (readonly)
Returns creation time of flag.
30 31 32 |
# File 'lib/rubyhexagon/post/flag.rb', line 30 def created_at @created_at end |
#id ⇒ Integer (readonly)
Returns id of flag.
27 28 29 |
# File 'lib/rubyhexagon/post/flag.rb', line 27 def id @id end |
#post ⇒ 621::Post (readonly)
Returns Post this flag is addressed to.
32 33 34 |
# File 'lib/rubyhexagon/post/flag.rb', line 32 def post @post end |
#reason ⇒ String (readonly)
Returns reason for flag.
34 35 36 |
# File 'lib/rubyhexagon/post/flag.rb', line 34 def reason @reason end |
#user ⇒ E621::User (readonly)
Returns User who flagged.
36 37 38 |
# File 'lib/rubyhexagon/post/flag.rb', line 36 def user @user end |
Class Method Details
.list(query) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/rubyhexagon/api/post/flag.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_flag_history, :index, query).map do |note| new(note) end end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for flags
73 74 75 |
# File 'lib/rubyhexagon/post/flag.rb', line 73 def ==(other) other.is_a?(E621::Post::Flag) && @id == other.id end |