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
Flag ID.
-
#post ⇒ 621::Post
readonly
Flag post.
-
#reason ⇒ String
readonly
Flagging reason.
-
#user ⇒ E621::User
readonly
User that initiated flagging.
Class Method Summary collapse
-
.list(query) ⇒ Array<E621::Flag>
Fetch a list of flags.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for flags.
-
#initialize(flag) ⇒ Object
constructor
Initializer for flags.
-
#to_hash ⇒ Hash
Turn object into a hash representation of itself.
Constructor Details
#initialize(flag) ⇒ Object
Initializer for flags
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rubyhexagon/post/flag.rb', line 66 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)
Creation time of flag
37 38 39 |
# File 'lib/rubyhexagon/post/flag.rb', line 37 def created_at @created_at end |
#id ⇒ Integer (readonly)
Flag ID
31 32 33 |
# File 'lib/rubyhexagon/post/flag.rb', line 31 def id @id end |
#post ⇒ 621::Post (readonly)
Flag post
43 44 45 |
# File 'lib/rubyhexagon/post/flag.rb', line 43 def post @post end |
#reason ⇒ String (readonly)
Flagging reason
49 50 51 |
# File 'lib/rubyhexagon/post/flag.rb', line 49 def reason @reason end |
#user ⇒ E621::User (readonly)
User that initiated flagging
55 56 57 |
# File 'lib/rubyhexagon/post/flag.rb', line 55 def user @user end |
Class Method Details
.list(query) ⇒ Array<E621::Flag>
Fetch a list of flags
35 36 37 38 39 40 41 42 |
# File 'lib/rubyhexagon/api/post/flag.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_flag_history, :index, query).map do |note| new(note) end end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for flags
96 97 98 |
# File 'lib/rubyhexagon/post/flag.rb', line 96 def ==(other) other.is_a?(E621::Post::Flag) && @id == other.id end |
#to_hash ⇒ Hash
Turn object into a hash representation of itself
107 108 109 110 111 112 113 |
# File 'lib/rubyhexagon/post/flag.rb', line 107 def to_hash hash = {} instance_variables.each do |i| hash.store(i.to_s.sub(/^@/, '').to_sym, instance_variable_get(i)) end hash end |