Class: ActiveRecall::Deck
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActiveRecall::Deck
- Includes:
- Base, Enumerable
- Defined in:
- lib/active_recall/models/deck.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<<(source) ⇒ Object
- #==(other) ⇒ Object
- #box(number) ⇒ Object
- #delete(source) ⇒ Object
- #each ⇒ Object
- #expired ⇒ Object
- #failed ⇒ Object
- #known ⇒ Object
- #last ⇒ Object
- #next ⇒ Object
- #review ⇒ Object
- #source_class ⇒ Object
- #untested ⇒ Object
Class Method Details
.add_deck(user) ⇒ Object
29 30 31 |
# File 'lib/active_recall/models/deck.rb', line 29 def self.add_deck(user) create!(user) end |
Instance Method Details
#<<(source) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/active_recall/models/deck.rb', line 19 def <<(source) attributes = {deck: self, source_id: source.id, source_type: source.class.name} if ActiveRecall::Item.exists?(attributes) raise ArgumentError, "Word already in the stack" end items << ActiveRecall::Item.new(attributes) end |
#==(other) ⇒ Object
15 16 17 |
# File 'lib/active_recall/models/deck.rb', line 15 def ==(other) _items == other end |
#box(number) ⇒ Object
67 68 69 |
# File 'lib/active_recall/models/deck.rb', line 67 def box(number) source_class.where(id: items.where(box: number).select(:source_id)) end |
#delete(source) ⇒ Object
33 34 35 36 37 |
# File 'lib/active_recall/models/deck.rb', line 33 def delete(source) ActiveRecall::Item .find_by(deck: self, source_id: source.id, source_type: source.class.name) .destroy end |
#each ⇒ Object
11 12 13 |
# File 'lib/active_recall/models/deck.rb', line 11 def each _items.find_each { |item| yield item } end |
#expired ⇒ Object
63 64 65 |
# File 'lib/active_recall/models/deck.rb', line 63 def expired source_class.where(id: items.expired.select(:source_id)) end |
#failed ⇒ Object
55 56 57 |
# File 'lib/active_recall/models/deck.rb', line 55 def failed source_class.where(id: items.failed.select(:source_id)) end |
#known ⇒ Object
59 60 61 |
# File 'lib/active_recall/models/deck.rb', line 59 def known source_class.where(id: items.known.select(:source_id)) end |
#last ⇒ Object
47 48 49 |
# File 'lib/active_recall/models/deck.rb', line 47 def last items.order("created_at desc").limit(1).first.try(:source) end |
#next ⇒ Object
43 44 45 |
# File 'lib/active_recall/models/deck.rb', line 43 def next _review.first.try(:source) end |
#review ⇒ Object
39 40 41 |
# File 'lib/active_recall/models/deck.rb', line 39 def review source_class.where(id: _review.select(:source_id)) end |
#source_class ⇒ Object
71 72 73 |
# File 'lib/active_recall/models/deck.rb', line 71 def source_class user.deck_name.to_s.singularize.titleize.constantize end |
#untested ⇒ Object
51 52 53 |
# File 'lib/active_recall/models/deck.rb', line 51 def untested source_class.where(id: items.untested.select(:source_id)) end |