Class: Katagen::Strategy::LeetCode

Inherits:
Object
  • Object
show all
Defined in:
lib/katagen/strategy/leetcode.rb

Overview

Generator for leetcode questions

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ LeetCode

Returns a new instance of LeetCode.

Raises:



19
20
21
22
# File 'lib/katagen/strategy/leetcode.rb', line 19

def initialize(id)
  @id = id.to_i
  raise InvalidIndex.new(@id) unless @id.positive?
end

Instance Method Details

#build_question_infoObject

Raises:



24
25
26
27
28
29
30
31
32
33
# File 'lib/katagen/strategy/leetcode.rb', line 24

def build_question_info
  summary = questions_summary.find { |q| q["id"] == @id }
  raise QuestionNotExist.new(@id) unless summary
  topic, difficulty = summary.values_at("topic", "difficulty")

  QuestionInfo.new(
    "#{difficulty}/#{@id}.#{topic}",
    "https:/leetcode.com/problems/#{topic}"
  )
end