Class: Rubyhexagon::Post::Flag

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyhexagon/post/flag.rb,
lib/rubyhexagon/api/post/flag.rb

Overview

A class to interact with the e621 web interface.

Author:

  • Maxine Michalski

Since:

  • 2.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flag) ⇒ Object

Initializer for flags

Parameters:

  • flag (Hash)

    flag data

Author:

  • Maxine Michalski

Since:

  • 2.0.0



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_atTime (readonly)

Returns creation time of flag.

Returns:

  • (Time)

    creation time of flag

Since:

  • 2.0.0



30
31
32
# File 'lib/rubyhexagon/post/flag.rb', line 30

def created_at
  @created_at
end

#idInteger (readonly)

Returns id of flag.

Returns:

  • (Integer)

    id of flag

Since:

  • 2.0.0



27
28
29
# File 'lib/rubyhexagon/post/flag.rb', line 27

def id
  @id
end

#post621::Post (readonly)

Returns Post this flag is addressed to.

Returns:

  • (621::Post)

    Post this flag is addressed to

Since:

  • 2.0.0



32
33
34
# File 'lib/rubyhexagon/post/flag.rb', line 32

def post
  @post
end

#reasonString (readonly)

Returns reason for flag.

Returns:

  • (String)

    reason for flag

Since:

  • 2.0.0



34
35
36
# File 'lib/rubyhexagon/post/flag.rb', line 34

def reason
  @reason
end

#userE621::User (readonly)

Returns User who flagged.

Returns:

Since:

  • 2.0.0



36
37
38
# File 'lib/rubyhexagon/post/flag.rb', line 36

def user
  @user
end

Class Method Details

.list(query) ⇒ Object

Since:

  • 2.0.0



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

Returns:

  • (TrueClass, FalseClass)

Author:

  • Maxine Michalski

Since:

  • 2.0.0



73
74
75
# File 'lib/rubyhexagon/post/flag.rb', line 73

def ==(other)
  other.is_a?(E621::Post::Flag) && @id == other.id
end