Class: Wanikani::SRS

Inherits:
Object
  • Object
show all
Defined in:
lib/wanikani/srs.rb

Constant Summary collapse

ITEM_TYPES =
%w(apprentice guru master enlighten burned all)

Class Method Summary collapse

Class Method Details

.distribution(item_type = "all") ⇒ Hash

Gets the counts for each SRS level and item types.

Parameters:

  • item_type (String) (defaults to: "all")

    the SRS level that will be returned.

Returns:

  • (Hash)

    Returns the SRS information for each level for the user.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
# File 'lib/wanikani/srs.rb', line 10

def self.distribution(item_type = "all")
  raise ArgumentError, "Please use a valid SRS type (or none for all types)" if !ITEM_TYPES.include?(item_type)

  api_response = Wanikani.api_response("srs-distribution")
  srs_distribution = api_response["requested_information"]

  return srs_distribution if item_type == "all"
  return srs_distribution[item_type]
end

.full_responseHash

Gets the full response of the SRS Distribution API call.

Returns:

  • (Hash)

    Full response from the SRS Distribution API call.



42
43
44
# File 'lib/wanikani/srs.rb', line 42

def self.full_response
  return Wanikani.api_response("srs-distribution")
end

.items_by_type(item_type) ⇒ Array

Gets all items for a specific SRS level.

Parameters:

  • item_type (String)

    the SRS level for the items returned.

Returns:

  • (Array)

    Returns all the items matching the specified SRS for each level for the user.

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/wanikani/srs.rb', line 24

def self.items_by_type(item_type)
  raise ArgumentError, "Please use a valid SRS type." if !ITEM_TYPES.include?(item_type) || item_type == "all"

  items_by_type = []
  %w(radicals kanji vocabulary).each do |type|
    items = Wanikani::Level.send(type)
    items.reject! { |item| item["user_specific"].nil? || item["user_specific"]["srs"] != item_type }.map! do |item|
      item.merge!("type" => (type == 'radicals' ? 'radical' : type))
    end
    items_by_type << items
  end

  items_by_type.flatten
end