Class: Wip::User
- Inherits:
-
Object
- Object
- Wip::User
- Defined in:
- lib/wip/user.rb
Instance Attribute Summary collapse
-
#avatar_url ⇒ Object
Returns the value of attribute avatar_url.
-
#best_streak ⇒ Object
Returns the value of attribute best_streak.
-
#completed_todos_count ⇒ Object
Returns the value of attribute completed_todos_count.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#streak ⇒ Object
Returns the value of attribute streak.
-
#streaking ⇒ Object
Returns the value of attribute streaking.
-
#time_zone ⇒ Object
Returns the value of attribute time_zone.
-
#todos ⇒ Object
Returns the value of attribute todos.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
- .default_selection(todos: {}) ⇒ Object
- .find(id = nil, username: nil, todos: {}) ⇒ Object
- .parse(data) ⇒ Object
- .viewer(todos: {}) ⇒ Object
Instance Method Summary collapse
- #done_todos ⇒ Object
-
#initialize(avatar_url: nil, best_streak: nil, completed_todos_count: nil, first_name: nil, id: nil, last_name: nil, streak: nil, streaking: nil, time_zone: nil, url: nil, username: nil, todos: []) ⇒ User
constructor
A new instance of User.
- #name ⇒ Object
- #streak_icon ⇒ Object
- #tz ⇒ Object
Constructor Details
#initialize(avatar_url: nil, best_streak: nil, completed_todos_count: nil, first_name: nil, id: nil, last_name: nil, streak: nil, streaking: nil, time_zone: nil, url: nil, username: nil, todos: []) ⇒ User
Returns a new instance of User.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wip/user.rb', line 49 def initialize(avatar_url: nil, best_streak: nil, completed_todos_count: nil, first_name: nil, id: nil, last_name: nil, streak: nil, streaking: nil, time_zone: nil, url: nil, username: nil, todos: []) @avatar_url = avatar_url @best_streak = best_streak @completed_todos_count = completed_todos_count @first_name = first_name @id = id @last_name = last_name @streak = streak @streaking = streaking @time_zone = time_zone @url = url @username = username @todos = todos end |
Instance Attribute Details
#avatar_url ⇒ Object
Returns the value of attribute avatar_url.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def avatar_url @avatar_url end |
#best_streak ⇒ Object
Returns the value of attribute best_streak.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def best_streak @best_streak end |
#completed_todos_count ⇒ Object
Returns the value of attribute completed_todos_count.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def completed_todos_count @completed_todos_count end |
#first_name ⇒ Object
Returns the value of attribute first_name.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def first_name @first_name end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def id @id end |
#last_name ⇒ Object
Returns the value of attribute last_name.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def last_name @last_name end |
#streak ⇒ Object
Returns the value of attribute streak.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def streak @streak end |
#streaking ⇒ Object
Returns the value of attribute streaking.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def streaking @streaking end |
#time_zone ⇒ Object
Returns the value of attribute time_zone.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def time_zone @time_zone end |
#todos ⇒ Object
Returns the value of attribute todos.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def todos @todos end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def url @url end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/wip/user.rb', line 6 def username @username end |
Class Method Details
.default_selection(todos: {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wip/user.rb', line 8 def self.default_selection(todos: {}) todos_selection = Wip::Todo.collection_query(**todos) %{ avatar_url best_streak completed_todos_count first_name id last_name streak streaking time_zone #{todos_selection} url username } end |
.find(id = nil, username: nil, todos: {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/wip/user.rb', line 37 def self.find(id = nil, username: nil, todos: {}) client = Wip::Client.new find_by = id.nil? ? "username: \"#{username}\"" : "id: #{id}" find_query = %{ { user(#{find_by}) {#{default_selection(todos: todos)}} } } client.request find_query parse client.data("user") end |
.parse(data) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wip/user.rb', line 64 def self.parse(data) new.tap do |user| data.each do |key, raw_value| value = case key when "id" raw_value.to_i when "todos" raw_value.collect { |v| Wip::Todo.parse v } else raw_value end user.send("#{key}=", value) end end end |
Instance Method Details
#done_todos ⇒ Object
99 100 101 |
# File 'lib/wip/user.rb', line 99 def done_todos todos.filter(&:done?) end |
#name ⇒ Object
80 81 82 |
# File 'lib/wip/user.rb', line 80 def name [first_name, last_name].join(" ") end |
#streak_icon ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/wip/user.rb', line 88 def streak_icon case streak when 0 "⛱" when 1..99 "🔥" else "🌶" end end |
#tz ⇒ Object
84 85 86 |
# File 'lib/wip/user.rb', line 84 def tz TZInfo::Timezone.get(time_zone) end |