Class: Rubyhexagon::User
- Inherits:
-
Object
- Object
- Rubyhexagon::User
- Defined in:
- lib/rubyhexagon/user.rb,
lib/rubyhexagon/api/user.rb,
lib/rubyhexagon/user/level.rb
Overview
A class to interact with the e621 web interface.
Defined Under Namespace
Classes: Level
Instance Attribute Summary collapse
-
#artist_tags ⇒ Array<E621::Tag>
readonly
An array of artist tags, associated with user.
-
#avatar ⇒ E621::Post
readonly
Avatar set by user.
-
#created_at ⇒ Time
readonly
Registration time of this user.
-
#id ⇒ Integer
readonly
Id of user.
-
#level ⇒ Level
readonly
Level of access, this user holds.
-
#name ⇒ String
readonly
Name of user.
Class Method Summary collapse
- .list(query) ⇒ Object
-
.show(user) ⇒ E621::User
Fetch data for user.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for User objects.
-
#initialize(user) ⇒ Object
constructor
Initializer for User.
- #show ⇒ Object
Constructor Details
#initialize(user) ⇒ Object
Initializer for User.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rubyhexagon/user.rb', line 52 def initialize(user) raise ArgumentError, "#{user.class} is not a Hash" unless user.is_a?(Hash) raise ArgumentError, 'Hash must include :id' if user[:id].nil? user.each do |k, v| if %i[id name].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 %i[created_at].include?(k) instance_variable_set("@#{k}".to_sym, Time.parse(v)) elsif k == :artist_tags @artist_tags = v.map { |t| E621::Tag.new(name: t) } elsif k == :avatar_id @avatar = E621::Post.new(id: v) end end end |
Instance Attribute Details
#artist_tags ⇒ Array<E621::Tag> (readonly)
Returns an array of artist tags, associated with user.
43 44 45 |
# File 'lib/rubyhexagon/user.rb', line 43 def @artist_tags end |
#avatar ⇒ E621::Post (readonly)
Returns avatar set by user.
40 41 42 |
# File 'lib/rubyhexagon/user.rb', line 40 def avatar @avatar end |
#created_at ⇒ Time (readonly)
Returns registration time of this user.
37 38 39 |
# File 'lib/rubyhexagon/user.rb', line 37 def created_at @created_at end |
#id ⇒ Integer (readonly)
Returns id of user.
28 29 30 |
# File 'lib/rubyhexagon/user.rb', line 28 def id @id end |
#level ⇒ Level (readonly)
Returns level of access, this user holds.
34 35 36 |
# File 'lib/rubyhexagon/user.rb', line 34 def level @level end |
#name ⇒ String (readonly)
Returns name of user.
31 32 33 |
# File 'lib/rubyhexagon/user.rb', line 31 def name @name end |
Class Method Details
.list(query) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/rubyhexagon/api/user.rb', line 41 def self.list(query) raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash) E621::API.fetch(:user, :index, query).map do |user| new(user) end end |
.show(user) ⇒ E621::User
Fetch data for user
32 33 34 35 36 37 38 39 |
# File 'lib/rubyhexagon/api/user.rb', line 32 def self.show(user) unless (user.is_a?(Hash) && user[:id].is_a?(Integer)) || user.is_a?(E621::User) raise ArgumentError, 'A Hash or user object are required' end user = user.is_a?(Hash) ? user : { id: user.id } new(E621::API.fetch(:user, :show, user)) end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for User objects
76 77 78 |
# File 'lib/rubyhexagon/user.rb', line 76 def ==(other) other.is_a?(User) && @id == other.id end |