saru 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +175 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/lib/saru.rb +22 -0
- data/lib/saru/builder.rb +46 -0
- data/lib/saru/connection.rb +23 -0
- data/lib/saru/connection/base.rb +62 -0
- data/lib/saru/connection/kanji.rb +13 -0
- data/lib/saru/connection/radical.rb +13 -0
- data/lib/saru/connection/vocabulary.rb +13 -0
- data/lib/saru/kanji.rb +34 -0
- data/lib/saru/list.rb +26 -0
- data/lib/saru/list/available_date.rb +38 -0
- data/lib/saru/list/incorrect.rb +58 -0
- data/lib/saru/list/kanji_related.rb +32 -0
- data/lib/saru/list/srs.rb +39 -0
- data/lib/saru/list/unlocked_date.rb +38 -0
- data/lib/saru/radical.rb +17 -0
- data/lib/saru/setup.rb +25 -0
- data/lib/saru/support/attributes.rb +18 -0
- data/lib/saru/support/time_converter.rb +13 -0
- data/lib/saru/version.rb +3 -0
- data/lib/saru/vocabulary.rb +21 -0
- data/saru.gemspec +29 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 54e40e1b2916336389bf2811d3e64aafc94fcb93
|
4
|
+
data.tar.gz: 7865d9d78b57022dfca8a761fe552b3e81a169d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 65f02843d3b4cac52fefe8ecac345d5af06a3e2d8254d2375c41957b83eb8ba69cda9d93e95cf7c432176d92d2d62b322c793a8ef114dc27d0353ff995df68c5
|
7
|
+
data.tar.gz: 1acafa17afe34e6a583603ec5e0af7c7f5337dabf8baecf448877239352e8e6f2d6557a23889ff82eb4216eebb275cea4f906ad9988a73d85546c2f9ea68740b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Victor
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
[](https://travis-ci.org/eltercero/saru)
|
2
|
+
|
3
|
+
# Saru (猿)
|
4
|
+
|
5
|
+
Saru (猿) is a wrapper for the Wanikani API, but it is focused on the SRS system, including a lot of searching methods not available in the API. If you're looking for a complete Wanikani API wrapper, check out [dennmart's great gem](https://github.com/dennmart/wanikani-gem).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To get the latest stable, add this to your Gemfile:
|
10
|
+
|
11
|
+
gem 'saru'
|
12
|
+
|
13
|
+
To get the latest code, add this:
|
14
|
+
|
15
|
+
gem 'saru', git: https://github.com/eltercero/saru
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install saru
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Setup
|
28
|
+
|
29
|
+
You'd need to add your API key before doing anything.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'saru'
|
33
|
+
|
34
|
+
# You can also have them in your env => ENV["WANIKANI_API_KEY"]
|
35
|
+
Saru.setup do |config|
|
36
|
+
config.api_key = 'your_api_key'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
### Request items using Wanikani API
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
require 'saru'
|
44
|
+
|
45
|
+
# With Saru you can replicate the API behaviour.
|
46
|
+
# For instance, let's get all Kanjis for the first level with
|
47
|
+
# the user's specific information
|
48
|
+
|
49
|
+
> kanjis_1 = Saru.kanji 1
|
50
|
+
=> #<Saru::List:0x007f871a1defb8
|
51
|
+
@items=
|
52
|
+
[#<Saru::Kanji:0x007f8719bc34a8
|
53
|
+
@available_date=1472052600,
|
54
|
+
@burned=true,
|
55
|
+
@burned_date=1472057541,
|
56
|
+
@character="二",
|
57
|
+
@important_reading="onyomi"
|
58
|
+
...
|
59
|
+
|
60
|
+
> first_kanji = kanjis_1.items.first
|
61
|
+
=> #<Saru::Kanji:0x007fa2b5a1c430
|
62
|
+
@available_date=1472052600,
|
63
|
+
@burned=true,
|
64
|
+
@burned_date=1472057541,
|
65
|
+
@character="二",
|
66
|
+
@important_reading="onyomi",
|
67
|
+
@kunyomi="ふた",
|
68
|
+
@level=1,
|
69
|
+
@meaning="two",
|
70
|
+
@meaning_correct=8
|
71
|
+
...
|
72
|
+
|
73
|
+
# You can also request more than one level. For example:
|
74
|
+
> kanjis_4_5 = Saru.kanji [4,5]
|
75
|
+
=> #<Saru::List:0x007f871a888df0
|
76
|
+
@items=
|
77
|
+
[#<Saru::Kanji:0x007f871a21c9f8
|
78
|
+
@available_date=1474518600,
|
79
|
+
@burned=true,
|
80
|
+
@burned_date=1474523699,
|
81
|
+
@character="花",
|
82
|
+
@important_reading="kunyomi",
|
83
|
+
@kunyomi="はな"
|
84
|
+
...
|
85
|
+
```
|
86
|
+
|
87
|
+
### Extended search
|
88
|
+
|
89
|
+
**Note:** These methods are not supported by Wanikani API queries. This means they are done _after_ the request in Wanikani.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
> Saru.vocabulary(20..25).unlocked_between(DateTime.parse('2017/01/01'), DateTime.parse('2017/02/01'))
|
93
|
+
=> #<Saru::List:0x007f8719c4e698
|
94
|
+
@items=
|
95
|
+
[#<Saru::Vocabulary:0x007f8719cdeb30
|
96
|
+
@available_date=1501066800,
|
97
|
+
@burned=false,
|
98
|
+
@burned_date=0,
|
99
|
+
@character="崎",
|
100
|
+
@kana="さき",
|
101
|
+
@level=23,
|
102
|
+
@meaning="cape, small peninsula"
|
103
|
+
...
|
104
|
+
|
105
|
+
# You can chain methods too.
|
106
|
+
|
107
|
+
> Saru.kanji(1..26).srs_is_not_burned.total_incorrect_larger_than(10)
|
108
|
+
=> #<Saru::List:0x007f871a92e368
|
109
|
+
@items=
|
110
|
+
[#<Saru::Kanji:0x007f871a339778
|
111
|
+
@available_date=1500118200,
|
112
|
+
@burned=false,
|
113
|
+
@burned_date=0,
|
114
|
+
@character="組",
|
115
|
+
@important_reading="onyomi",
|
116
|
+
@kunyomi="くみ"
|
117
|
+
...
|
118
|
+
```
|
119
|
+
|
120
|
+
### Available search methods
|
121
|
+
|
122
|
+
#### SRS
|
123
|
+
* List#srs_numeric_larger_than(number)
|
124
|
+
* List#srs_numeric_smaller_than(number)
|
125
|
+
* List#srs_in(states)
|
126
|
+
* List#srs_is_apprentice
|
127
|
+
* List#srs_is_guru
|
128
|
+
* List#srs_is_master
|
129
|
+
* List#srs_is_enlighten
|
130
|
+
* List#srs_is_burned
|
131
|
+
* List#srs_is_not_apprentice
|
132
|
+
* List#srs_is_not_guru
|
133
|
+
* List#srs_is_not_master
|
134
|
+
* List#srs_is_not_enlighten
|
135
|
+
* List#srs_is_not_burned
|
136
|
+
|
137
|
+
#### Unlocked date
|
138
|
+
* List#unlocked_after(date)
|
139
|
+
* List#unlocked_before(date)
|
140
|
+
* List#unlocked_between(start_date, end_date)
|
141
|
+
|
142
|
+
#### Available date
|
143
|
+
* List#available_after(date)
|
144
|
+
* List#available_before(date)
|
145
|
+
* List#available_between(start_date, end_date)
|
146
|
+
|
147
|
+
#### Incorrect counters
|
148
|
+
* List#meaning_incorrect_larger_than(number)
|
149
|
+
* List#meaning_incorrect_smaller_than(number)
|
150
|
+
* List#reading_incorrect_larger_than(number)
|
151
|
+
* List#reading_incorrect_smaller_than(number)
|
152
|
+
* List#total_incorrect_larger_than(number)
|
153
|
+
* List#total_incorrect_smaller_than(number)
|
154
|
+
|
155
|
+
#### Kanji Related (only for Kanji requests)
|
156
|
+
* List#onyomi_is(reading)
|
157
|
+
* List#kunyomi_is(reading)
|
158
|
+
* List#important_reading_is(reading)
|
159
|
+
|
160
|
+
## Contributing
|
161
|
+
|
162
|
+
What? Really? So nice of you for considering, you are the best.
|
163
|
+
|
164
|
+
I could really use a hand adding more modules for Saru::List so it could be more helpful. Right now there are many radical/kanji/vocabulary attributes without a search method.
|
165
|
+
|
166
|
+
1. Fork it ( http://github.com/eltercero/saru/fork )
|
167
|
+
2. Create your feature branch (`git checkout -b missing_features`)
|
168
|
+
3. Commit your changes (`git commit -am 'いいといいですね!'`). Don't forget to add a spec!
|
169
|
+
4. Push to the branch (`git push origin missing_features`)
|
170
|
+
5. Create new Pull Request
|
171
|
+
|
172
|
+
## License
|
173
|
+
|
174
|
+
Released under the [MIT License](http://opensource.org/licenses/MIT).
|
175
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/saru.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "saru/connection"
|
2
|
+
require "saru/builder"
|
3
|
+
|
4
|
+
require "saru/setup"
|
5
|
+
require "saru/version"
|
6
|
+
|
7
|
+
module Saru
|
8
|
+
extend self
|
9
|
+
extend Setup
|
10
|
+
|
11
|
+
def radicals levels=nil
|
12
|
+
Builder.new('radical', levels).call
|
13
|
+
end
|
14
|
+
|
15
|
+
def kanji levels=nil
|
16
|
+
Builder.new('kanji', levels).call
|
17
|
+
end
|
18
|
+
|
19
|
+
def vocabulary levels=nil
|
20
|
+
Builder.new('vocabulary', levels).call
|
21
|
+
end
|
22
|
+
end
|
data/lib/saru/builder.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'saru/list'
|
2
|
+
require 'saru/radical'
|
3
|
+
require 'saru/kanji'
|
4
|
+
require 'saru/vocabulary'
|
5
|
+
|
6
|
+
module Saru
|
7
|
+
class Builder
|
8
|
+
TYPES = %w(radical kanji vocabulary)
|
9
|
+
|
10
|
+
attr_reader :type, :levels
|
11
|
+
|
12
|
+
def initialize type, levels = nil
|
13
|
+
@type = type
|
14
|
+
@levels = levels
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
raise ArgumentError, 'Not valid type' unless TYPES.include?(type)
|
19
|
+
|
20
|
+
build
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def build
|
26
|
+
request_items = request['requested_information']
|
27
|
+
items = request_items.map{|item| build_class.new flatten(item) }
|
28
|
+
|
29
|
+
List.new items
|
30
|
+
end
|
31
|
+
|
32
|
+
def request
|
33
|
+
Connection.send(type, levels)
|
34
|
+
end
|
35
|
+
|
36
|
+
def build_class
|
37
|
+
Module.const_get "Saru::#{type.capitalize}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def flatten item
|
41
|
+
item.merge!(item['user_specific']) if item['user_specific']
|
42
|
+
item.delete_if{|key, _value| key == 'user_specific' }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'saru/connection/base'
|
2
|
+
require 'saru/connection/radical'
|
3
|
+
require 'saru/connection/kanji'
|
4
|
+
require 'saru/connection/vocabulary'
|
5
|
+
|
6
|
+
module Saru
|
7
|
+
module Connection
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def radical levels=nil
|
11
|
+
Radical.new(levels).call
|
12
|
+
end
|
13
|
+
|
14
|
+
def kanji levels=nil
|
15
|
+
Kanji.new(levels).call
|
16
|
+
end
|
17
|
+
|
18
|
+
def vocabulary levels=nil
|
19
|
+
Vocabulary.new(levels).call
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Saru
|
5
|
+
module Connection
|
6
|
+
class Base
|
7
|
+
|
8
|
+
ENDPOINT_HOST = "https://www.wanikani.com"
|
9
|
+
ENDPOINT_BASE = "/api/user"
|
10
|
+
|
11
|
+
WanikaniConnectionError = Class.new(StandardError)
|
12
|
+
|
13
|
+
attr_reader :levels
|
14
|
+
|
15
|
+
def initialize levels
|
16
|
+
@levels = levels
|
17
|
+
end
|
18
|
+
|
19
|
+
def call
|
20
|
+
response.status == 200 ? content : raise_error
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def response
|
26
|
+
raise ArgumentError, 'Missing API key' unless Saru.valid?
|
27
|
+
@response ||= connection.get path
|
28
|
+
end
|
29
|
+
|
30
|
+
def content
|
31
|
+
@content ||= JSON.parse(response.body)
|
32
|
+
end
|
33
|
+
|
34
|
+
def connection
|
35
|
+
@connection ||= Faraday.new ENDPOINT_HOST do |connection|
|
36
|
+
connection.headers[ 'Content-Type' ] = 'application/json'
|
37
|
+
connection.adapter :net_http
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def base_path
|
42
|
+
"#{ENDPOINT_BASE}/#{Saru.api_key}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def levels_request
|
46
|
+
Array(levels).join(',')
|
47
|
+
end
|
48
|
+
|
49
|
+
def raise_error
|
50
|
+
raise WanikaniConnectionError, %Q{
|
51
|
+
Wanikani responded with #{response.status} (expecting 200)
|
52
|
+
|
53
|
+
request: GET #{path}
|
54
|
+
|
55
|
+
response:
|
56
|
+
#{response.inspect}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/saru/kanji.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'saru/support/attributes'
|
2
|
+
|
3
|
+
module Saru
|
4
|
+
class Kanji
|
5
|
+
include Saru::Support::Attributes
|
6
|
+
|
7
|
+
attr_reader :character, :kana, :meaning, :onyomi, :kunyomi,
|
8
|
+
:important_reading, :level, :nanori,
|
9
|
+
:unlocked_date, :user_synonyms, :meaning_note,
|
10
|
+
:reading_note, :srs, :srs_numeric, :available_date,
|
11
|
+
:burned, :burned_date, :reactivated_date,
|
12
|
+
:meaning_correct, :meaning_incorrect,
|
13
|
+
:meaning_max_streak, :meaning_current_streak,
|
14
|
+
:reading_correct, :reading_incorrect,
|
15
|
+
:reading_max_streak, :reading_current_streak
|
16
|
+
|
17
|
+
def wanikani_reading
|
18
|
+
send important_reading
|
19
|
+
end
|
20
|
+
|
21
|
+
def kunyomis
|
22
|
+
kunyomi.to_s.split(',').map(&:strip)
|
23
|
+
end
|
24
|
+
|
25
|
+
def onyomis
|
26
|
+
onyomi.to_s.split(',').map(&:strip)
|
27
|
+
end
|
28
|
+
|
29
|
+
def meanings
|
30
|
+
meaning.to_s.split(',').map(&:strip)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/saru/list.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'saru/list/available_date'
|
2
|
+
require 'saru/list/unlocked_date'
|
3
|
+
require 'saru/list/incorrect'
|
4
|
+
require 'saru/list/srs'
|
5
|
+
require 'saru/list/kanji_related'
|
6
|
+
|
7
|
+
module Saru
|
8
|
+
class List
|
9
|
+
extend Forwardable
|
10
|
+
include Saru::List::AvailableDate
|
11
|
+
include Saru::List::UnlockedDate
|
12
|
+
include Saru::List::Incorrect
|
13
|
+
include Saru::List::Srs
|
14
|
+
include Saru::List::KanjiRelated
|
15
|
+
|
16
|
+
attr_reader :items
|
17
|
+
|
18
|
+
def initialize items
|
19
|
+
@items = items
|
20
|
+
end
|
21
|
+
|
22
|
+
def_delegator :@items,
|
23
|
+
:size
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'saru/support/time_converter'
|
2
|
+
|
3
|
+
module Saru
|
4
|
+
class List
|
5
|
+
module AvailableDate
|
6
|
+
include Saru::Support::TimeConverter
|
7
|
+
|
8
|
+
def available_after date
|
9
|
+
selected = items.select do |item|
|
10
|
+
!item.available_date.nil? &&
|
11
|
+
item.available_date > to_unix(date)
|
12
|
+
end
|
13
|
+
|
14
|
+
Saru::List.new selected
|
15
|
+
end
|
16
|
+
|
17
|
+
def available_before date
|
18
|
+
selected = items.select do |item|
|
19
|
+
!item.available_date.nil? &&
|
20
|
+
item.available_date < to_unix(date)
|
21
|
+
end
|
22
|
+
|
23
|
+
Saru::List.new selected
|
24
|
+
end
|
25
|
+
|
26
|
+
def avaliable_between start_date, end_date
|
27
|
+
selected = items.select do |item|
|
28
|
+
!item.unlocked_date.nil? &&
|
29
|
+
item.available_date > to_unix(start_date) &&
|
30
|
+
item.available_date < to_unix(end_date)
|
31
|
+
end
|
32
|
+
|
33
|
+
Saru::List.new selected
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Saru
|
2
|
+
class List
|
3
|
+
module Incorrect
|
4
|
+
|
5
|
+
# Meaning
|
6
|
+
def meaning_incorrect_larger_than number
|
7
|
+
selected = items.select do |item|
|
8
|
+
item.meaning_incorrect.to_i > number
|
9
|
+
end
|
10
|
+
Saru::List.new selected
|
11
|
+
end
|
12
|
+
|
13
|
+
def meaning_incorrect_smaller_than number
|
14
|
+
selected = items.select do |item|
|
15
|
+
!item.meaning_incorrect.nil? &&
|
16
|
+
item.meaning_incorrect < number
|
17
|
+
end
|
18
|
+
Saru::List.new selected
|
19
|
+
end
|
20
|
+
|
21
|
+
# Reading
|
22
|
+
def reading_incorrect_larger_than number
|
23
|
+
selected = items.select do |item|
|
24
|
+
item.reading_incorrect.to_i > number
|
25
|
+
end
|
26
|
+
Saru::List.new selected
|
27
|
+
end
|
28
|
+
|
29
|
+
def reading_incorrect_smaller_than number
|
30
|
+
selected = items.select do |item|
|
31
|
+
!item.reading_incorrect.nil? &&
|
32
|
+
item.reading_incorrect < number
|
33
|
+
end
|
34
|
+
Saru::List.new selected
|
35
|
+
end
|
36
|
+
|
37
|
+
# Total
|
38
|
+
def total_incorrect_larger_than number
|
39
|
+
selected = items.select do |item|
|
40
|
+
total_incorrect = item.meaning_incorrect.to_i + item.reading_incorrect.to_i
|
41
|
+
total_incorrect > number
|
42
|
+
end
|
43
|
+
Saru::List.new selected
|
44
|
+
end
|
45
|
+
|
46
|
+
def total_incorrect_smaller_than number
|
47
|
+
selected = items.select do |item|
|
48
|
+
!item.meaning_incorrect.nil? &&
|
49
|
+
!item.reading_incorrect.nil? &&
|
50
|
+
(item.meaning_incorrect + item.reading_incorrect) < number
|
51
|
+
end
|
52
|
+
|
53
|
+
Saru::List.new selected
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Saru
|
2
|
+
class List
|
3
|
+
module KanjiRelated
|
4
|
+
|
5
|
+
def important_reading_is reading
|
6
|
+
kunyomi = kunyomi_is(reading).items
|
7
|
+
onyomi = onyomi_is(reading).items
|
8
|
+
|
9
|
+
Saru::List.new kunyomi+onyomi
|
10
|
+
end
|
11
|
+
|
12
|
+
def onyomi_is onyomi
|
13
|
+
selected = items.select do |item|
|
14
|
+
item.is_a?(Saru::Kanji) &&
|
15
|
+
item.onyomis.include?(onyomi)
|
16
|
+
end
|
17
|
+
|
18
|
+
Saru::List.new selected
|
19
|
+
end
|
20
|
+
|
21
|
+
def kunyomi_is kunyomi
|
22
|
+
selected = items.select do |item|
|
23
|
+
item.is_a?(Saru::Kanji) &&
|
24
|
+
item.kunyomis.include?(kunyomi)
|
25
|
+
end
|
26
|
+
|
27
|
+
Saru::List.new selected
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Saru
|
2
|
+
class List
|
3
|
+
module Srs
|
4
|
+
|
5
|
+
def srs_numeric_larger_than number
|
6
|
+
selected = items.select do |item|
|
7
|
+
!item.srs_numeric.nil? &&
|
8
|
+
item.srs_numeric > number
|
9
|
+
end
|
10
|
+
|
11
|
+
Saru::List.new selected
|
12
|
+
end
|
13
|
+
|
14
|
+
def srs_numeric_smaller_than number
|
15
|
+
selected = items.select do |item|
|
16
|
+
!item.srs_numeric.nil? &&
|
17
|
+
item.srs_numeric < number
|
18
|
+
end
|
19
|
+
|
20
|
+
Saru::List.new selected
|
21
|
+
end
|
22
|
+
|
23
|
+
def srs_in states
|
24
|
+
Saru::List.new items.select{|item| states.include? item.srs }
|
25
|
+
end
|
26
|
+
|
27
|
+
%w(apprentice guru master enlighten burned).each do |state|
|
28
|
+
define_method "srs_is_#{state}".to_sym do
|
29
|
+
Saru::List.new items.select{|item| item.srs == state }
|
30
|
+
end
|
31
|
+
|
32
|
+
define_method "srs_is_not_#{state}".to_sym do
|
33
|
+
Saru::List.new items.select{|item| item.srs != state }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'saru/support/time_converter'
|
2
|
+
|
3
|
+
module Saru
|
4
|
+
class List
|
5
|
+
module UnlockedDate
|
6
|
+
include Saru::Support::TimeConverter
|
7
|
+
|
8
|
+
def unlocked_after date
|
9
|
+
selected = items.select do |item|
|
10
|
+
!item.unlocked_date.nil? &&
|
11
|
+
item.unlocked_date > to_unix(date)
|
12
|
+
end
|
13
|
+
|
14
|
+
Saru::List.new selected
|
15
|
+
end
|
16
|
+
|
17
|
+
def unlocked_before date
|
18
|
+
selected = items.select do |item|
|
19
|
+
!item.unlocked_date.nil? &&
|
20
|
+
item.unlocked_date < to_unix(date)
|
21
|
+
end
|
22
|
+
|
23
|
+
Saru::List.new selected
|
24
|
+
end
|
25
|
+
|
26
|
+
def unlocked_between start_date, end_date
|
27
|
+
selected = items.select do |item|
|
28
|
+
!item.unlocked_date.nil? &&
|
29
|
+
item.unlocked_date > to_unix(start_date) &&
|
30
|
+
item.unlocked_date < to_unix(end_date)
|
31
|
+
end
|
32
|
+
|
33
|
+
Saru::List.new selected
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/saru/radical.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'saru/support/attributes'
|
2
|
+
|
3
|
+
module Saru
|
4
|
+
class Radical
|
5
|
+
include Saru::Support::Attributes
|
6
|
+
|
7
|
+
attr_reader :character, :meaning, :image, :level,
|
8
|
+
:unlocked_date, :user_synonyms, :meaning_note,
|
9
|
+
:reading_note, :srs, :srs_numeric, :available_date,
|
10
|
+
:burned, :burned_date, :reactivated_date,
|
11
|
+
:meaning_correct, :meaning_incorrect,
|
12
|
+
:meaning_max_streak, :meaning_current_streak,
|
13
|
+
:reading_correct, :reading_incorrect,
|
14
|
+
:reading_max_streak, :reading_current_streak
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/saru/setup.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Saru
|
2
|
+
module Setup
|
3
|
+
|
4
|
+
API_KEY = ENV["WANIKANI_API_KEY"]
|
5
|
+
|
6
|
+
attr_accessor :api_key
|
7
|
+
|
8
|
+
def self.extended(base)
|
9
|
+
base.set
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
yield self
|
14
|
+
end
|
15
|
+
|
16
|
+
def set
|
17
|
+
self.api_key = API_KEY
|
18
|
+
end
|
19
|
+
|
20
|
+
def valid?
|
21
|
+
!api_key.nil? && api_key != ''
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Saru
|
2
|
+
module Support
|
3
|
+
module Attributes
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
assign_attributes args
|
7
|
+
end
|
8
|
+
|
9
|
+
def assign_attributes args
|
10
|
+
args.each do |attribute, value|
|
11
|
+
instance_variable_set("@#{attribute}", value) unless value.nil?
|
12
|
+
end
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/saru/version.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'saru/support/attributes'
|
2
|
+
|
3
|
+
module Saru
|
4
|
+
class Vocabulary
|
5
|
+
include Saru::Support::Attributes
|
6
|
+
|
7
|
+
attr_reader :character, :kana, :meaning, :level,
|
8
|
+
:unlocked_date, :user_synonyms, :meaning_note,
|
9
|
+
:reading_note, :srs, :srs_numeric, :available_date,
|
10
|
+
:burned, :burned_date, :reactivated_date,
|
11
|
+
:meaning_correct, :meaning_incorrect,
|
12
|
+
:meaning_max_streak, :meaning_current_streak,
|
13
|
+
:reading_correct, :reading_incorrect,
|
14
|
+
:reading_max_streak, :reading_current_streak
|
15
|
+
|
16
|
+
def meanings
|
17
|
+
meaning.to_s.split(',').map(&:strip)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/saru.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'saru/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "saru"
|
8
|
+
spec.version = Saru::VERSION
|
9
|
+
spec.authors = ["Víctor"]
|
10
|
+
spec.email = ["victor.martin84@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Wanikani SRS items API Wrapper.}
|
13
|
+
spec.description = %q{Wanikani API Wrapper for the user's items (radicals, kanji and vocabulary)}
|
14
|
+
spec.homepage = "https://github.com/eltercero/saru"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
25
|
+
spec.add_development_dependency "faraday", '~>0.9'
|
26
|
+
spec.add_development_dependency "json", '~>1.8'
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: saru
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Víctor
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Wanikani API Wrapper for the user's items (radicals, kanji and vocabulary)
|
84
|
+
email:
|
85
|
+
- victor.martin84@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- lib/saru.rb
|
100
|
+
- lib/saru/builder.rb
|
101
|
+
- lib/saru/connection.rb
|
102
|
+
- lib/saru/connection/base.rb
|
103
|
+
- lib/saru/connection/kanji.rb
|
104
|
+
- lib/saru/connection/radical.rb
|
105
|
+
- lib/saru/connection/vocabulary.rb
|
106
|
+
- lib/saru/kanji.rb
|
107
|
+
- lib/saru/list.rb
|
108
|
+
- lib/saru/list/available_date.rb
|
109
|
+
- lib/saru/list/incorrect.rb
|
110
|
+
- lib/saru/list/kanji_related.rb
|
111
|
+
- lib/saru/list/srs.rb
|
112
|
+
- lib/saru/list/unlocked_date.rb
|
113
|
+
- lib/saru/radical.rb
|
114
|
+
- lib/saru/setup.rb
|
115
|
+
- lib/saru/support/attributes.rb
|
116
|
+
- lib/saru/support/time_converter.rb
|
117
|
+
- lib/saru/version.rb
|
118
|
+
- lib/saru/vocabulary.rb
|
119
|
+
- saru.gemspec
|
120
|
+
homepage: https://github.com/eltercero/saru
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.6.11
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Wanikani SRS items API Wrapper.
|
144
|
+
test_files: []
|