Class: Leetcoder::SubmissionsResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Leetcoder::SubmissionsResource
- Defined in:
- lib/leetcoder/leetcoder/resources/submissions.rb
Instance Attribute Summary
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#accepted_list ⇒ Object
returns a list of accepted submissions of the problem.
-
#list ⇒ Object
returns a list of all the submissions for a problem.
-
#retrieve(url:) ⇒ Object
returns the html object for a single submission.
-
#uniq_accepted_list ⇒ Object
returns a list of latest accepted submission from each language.
Methods inherited from BaseResource
#cache_response, #get_request, #gql_request, #initialize, #post_request
Methods included from Helpers::GqlQueries
#default_limit, #problemset_query, #question_data_query, #submissions_query
Constructor Details
This class inherits a constructor from Leetcoder::BaseResource
Instance Method Details
#accepted_list ⇒ Object
returns a list of accepted submissions of the problem
13 14 15 16 17 |
# File 'lib/leetcoder/leetcoder/resources/submissions.rb', line 13 def accepted_list @accepted_list ||= list.select do |submission| submission.statusDisplay == 'Accepted' end end |
#list ⇒ Object
returns a list of all the submissions for a problem
6 7 8 9 10 |
# File 'lib/leetcoder/leetcoder/resources/submissions.rb', line 6 def list response = gql_request(query: submissions_query(**args.slice(:title_slug))) Collection.from_response(response.body, key: %i[data submissionList submissions]) end |
#retrieve(url:) ⇒ Object
returns the html object for a single submission
27 28 29 30 31 |
# File 'lib/leetcoder/leetcoder/resources/submissions.rb', line 27 def retrieve(url:) response = get_request(url) Object.from_html(response.body) end |
#uniq_accepted_list ⇒ Object
returns a list of latest accepted submission from each language
20 21 22 23 24 |
# File 'lib/leetcoder/leetcoder/resources/submissions.rb', line 20 def uniq_accepted_list accepted_list .group_by(&:lang) .map { |x| x[1].first } end |