Class: Renshuu::Schedule
- Defined in:
- lib/renshuu/models/schedule.rb
Overview
Model class for schedules.
Defined Under Namespace
Classes: NewTermCount, TermCount, TodayCount, UpcomingCount
Constant Summary collapse
- BOOKTYPES =
Mapping between schedule booktypes and model classes.
{ 'kanji' => Kanji, 'vocab' => Word, 'grammar' => Grammar, 'sent' => Sentence }.freeze
Instance Attribute Summary collapse
- #booktype ⇒ String readonly
- #id ⇒ String readonly
- #is_frozen ⇒ Boolean readonly
- #name ⇒ String readonly
- #new_terms ⇒ NewTermCount readonly
- #terms ⇒ TermCount readonly
-
#today ⇒ Object
readonly
rn [TodayCount].
- #upcoming ⇒ Array<UpcomingCount> readonly
Class Method Summary collapse
-
.get(id) ⇒ Schedule
Retrieves a specific schedule from the API.
-
.list ⇒ Array<Schedule>
Lists all schedules of the current user.
Instance Method Summary collapse
-
#add(item) ⇒ Void
Adds the given item to the schedule.
-
#contents(page: nil, group: nil) ⇒ Array<Kanji,Word,Grammar,Sentence>
Retrieves the terms contained in the schedule.
-
#remove(item) ⇒ Void
Removes the given item from the schedule.
-
#term_class ⇒ Class
Model class to use for this schedule’s terms.
Instance Attribute Details
#booktype ⇒ String (readonly)
54 |
# File 'lib/renshuu/models/schedule.rb', line 54 attribute :booktype, Types::String |
#id ⇒ String (readonly)
46 |
# File 'lib/renshuu/models/schedule.rb', line 46 attribute :id, Types::String |
#is_frozen ⇒ Boolean (readonly)
58 |
# File 'lib/renshuu/models/schedule.rb', line 58 attribute :is_frozen, Types::Params::Bool |
#name ⇒ String (readonly)
50 |
# File 'lib/renshuu/models/schedule.rb', line 50 attribute :name, Types::String |
#new_terms ⇒ NewTermCount (readonly)
139 |
# File 'lib/renshuu/models/schedule.rb', line 139 attribute :new_terms, NewTermCount |
#terms ⇒ TermCount (readonly)
122 |
# File 'lib/renshuu/models/schedule.rb', line 122 attribute :terms, TermCount |
#today ⇒ Object (readonly)
rn [TodayCount]
80 |
# File 'lib/renshuu/models/schedule.rb', line 80 attribute :today, TodayCount |
#upcoming ⇒ Array<UpcomingCount> (readonly)
97 |
# File 'lib/renshuu/models/schedule.rb', line 97 attribute :upcoming, Types::Array.of(UpcomingCount) |
Class Method Details
Instance Method Details
#add(item) ⇒ Void
Adds the given item to the schedule.
169 170 171 172 173 174 175 |
# File 'lib/renshuu/models/schedule.rb', line 169 def add(item) unless item.is_a?(term_class) raise ArgumentError, "Expected a `#{term_class}`, got a `#{item.class}`" end item.add_to_schedule(self) end |
#contents(page: nil, group: nil) ⇒ Array<Kanji,Word,Grammar,Sentence>
Retrieves the terms contained in the schedule.
152 153 154 155 156 157 |
# File 'lib/renshuu/models/schedule.rb', line 152 def contents(page: nil, group: nil) params = { pg: page, group: }.compact body = Renshuu.client.query(:get, "v1/schedule/#{id}/list", params:) body.dig(:contents, :terms).map { term_class.new(_1) } end |
#remove(item) ⇒ Void
Removes the given item from the schedule.
187 188 189 190 191 192 193 |
# File 'lib/renshuu/models/schedule.rb', line 187 def remove(item) unless item.is_a?(term_class) raise ArgumentError, "Expected a `#{term_class}`, got a `#{item.class}`" end item.remove_from_schedule(self) end |
#term_class ⇒ Class
Model class to use for this schedule’s terms.
202 203 204 205 206 |
# File 'lib/renshuu/models/schedule.rb', line 202 def term_class @term_class ||= BOOKTYPES.fetch(booktype) do |key| raise KeyError, "Unkown schedule type `#{key}`" end end |