class Wip::User
Attributes
avatar_url[RW]
best_streak[RW]
completed_todos_count[RW]
first_name[RW]
id[RW]
last_name[RW]
streak[RW]
streaking[RW]
time_zone[RW]
todos[RW]
url[RW]
username[RW]
Public Class Methods
default_selection(todos: {})
click to toggle source
# 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: {})
click to toggle source
# 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
new(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: [])
click to toggle source
# 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
parse(data)
click to toggle source
# 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
viewer(todos: {})
click to toggle source
# File lib/wip/user.rb, line 26 def self.viewer(todos: {}) client = Wip::Client.new find_query = %{ { viewer {#{default_selection(todos: todos)}} } } client.request find_query parse client.data("viewer") end
Public Instance Methods
done_todos()
click to toggle source
# File lib/wip/user.rb, line 99 def done_todos todos.filter(&:done?) end
name()
click to toggle source
# File lib/wip/user.rb, line 80 def name [first_name, last_name].join(" ") end
streak_icon()
click to toggle source
# File lib/wip/user.rb, line 88 def streak_icon case streak when 0 "⛱" when 1..99 "🔥" else "🌶" end end
tz()
click to toggle source
# File lib/wip/user.rb, line 84 def tz TZInfo::Timezone.get(time_zone) end