Class: MijDiscord::Data::Game
- Inherits:
-
Object
- Object
- MijDiscord::Data::Game
- Defined in:
- lib/mij-discord/data/user.rb
Constant Summary collapse
- PLAYING_TYPE =
[ :playing, :streaming, :listening, :watching, ].freeze
Instance Attribute Summary collapse
-
#application ⇒ Object
readonly
Returns the value of attribute application.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#large_image ⇒ Object
readonly
Returns the value of attribute large_image.
-
#large_text ⇒ Object
readonly
Returns the value of attribute large_text.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#small_image ⇒ Object
readonly
Returns the value of attribute small_image.
-
#small_text ⇒ Object
readonly
Returns the value of attribute small_text.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Game
constructor
A new instance of Game.
- #inspect ⇒ Object
- #to_hash ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(data) ⇒ Game
Returns a new instance of Game.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mij-discord/data/user.rb', line 38 def initialize(data) @type = data['type'] @name = data['name'] @url = data['url'] @details = data['details'] @state = data['state'] @application = data['application_id'] if (start_time = data.dig('timestamps', 'start')) @start_time = Time.at(start_time.to_i).utc end if (end_time = data.dig('timestamps', 'end')) @end_time = Time.at(end_time.to_i).utc end if (assets = data['assets']) @large_image = assets['large_image'] @large_text = assets['large_text'] @small_image = assets['small_image'] @small_text = assets['small_text'] end end |
Instance Attribute Details
#application ⇒ Object (readonly)
Returns the value of attribute application.
24 25 26 |
# File 'lib/mij-discord/data/user.rb', line 24 def application @application end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
16 17 18 |
# File 'lib/mij-discord/data/user.rb', line 16 def details @details end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
22 23 24 |
# File 'lib/mij-discord/data/user.rb', line 22 def end_time @end_time end |
#large_image ⇒ Object (readonly)
Returns the value of attribute large_image.
26 27 28 |
# File 'lib/mij-discord/data/user.rb', line 26 def large_image @large_image end |
#large_text ⇒ Object (readonly)
Returns the value of attribute large_text.
28 29 30 |
# File 'lib/mij-discord/data/user.rb', line 28 def large_text @large_text end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/mij-discord/data/user.rb', line 12 def name @name end |
#small_image ⇒ Object (readonly)
Returns the value of attribute small_image.
30 31 32 |
# File 'lib/mij-discord/data/user.rb', line 30 def small_image @small_image end |
#small_text ⇒ Object (readonly)
Returns the value of attribute small_text.
32 33 34 |
# File 'lib/mij-discord/data/user.rb', line 32 def small_text @small_text end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
20 21 22 |
# File 'lib/mij-discord/data/user.rb', line 20 def start_time @start_time end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
18 19 20 |
# File 'lib/mij-discord/data/user.rb', line 18 def state @state end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
14 15 16 |
# File 'lib/mij-discord/data/user.rb', line 14 def url @url end |
Class Method Details
.construct(data) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/mij-discord/data/user.rb', line 86 def self.construct(data) data = {name: data} if data.is_a?(String) times = { 'start' => data.try_keys(:start_time, 'start_time')&.to_i, 'end' => data.try_keys(:end_time, 'end_time')&.to_i, }.delete_if {|_,v| v.nil? } assets = { 'large_image' => data.try_keys(:large_image, 'large_image')&.to_s, 'large_text' => data.try_keys(:large_text, 'large_text')&.to_s, 'small_image' => data.try_keys(:small_image, 'small_image')&.to_s, 'small_text' => data.try_keys(:small_text, 'small_text')&.to_s, }.delete_if {|_,v| v.nil? } game = { 'type' => PLAYING_TYPE.index(data.try_keys(:type, 'type')).to_i, 'name' => data.try_keys(:name, 'name')&.to_s, 'url' => data.try_keys(:url, 'url')&.to_s, 'details' => data.try_keys(:details, 'details')&.to_s, 'state' => data.try_keys(:state, 'state')&.to_s, 'application_id' => data.try_keys(:application, 'application')&.to_s, 'timestamps' => times.empty? ? nil : times, 'assets' => assets.empty? ? nil : assets, }.delete_if {|_,v| v.nil? } game end |
Instance Method Details
#inspect ⇒ Object
80 81 82 83 84 |
# File 'lib/mij-discord/data/user.rb', line 80 def inspect MijDiscord.make_inspect(self, :type, :name, :url, :details, :state, :start_time, :end_time, :application, :large_image, :large_text, :small_image, :small_text) end |
#to_hash ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mij-discord/data/user.rb', line 61 def to_hash self.class.construct({ start_time: @start_time, end_time: @end_time, large_image: @large_image, large_text: @large_text, small_image: @small_image, small_text: @small_text, type: @type, name: @name, url: @url, details: @details, state: @state, application: @application, }) end |
#type ⇒ Object
34 35 36 |
# File 'lib/mij-discord/data/user.rb', line 34 def type PLAYING_TYPE[@type] end |