Class: KeepYourHead::Database::Flashcard

Inherits:
BaseItemWithXml show all
Defined in:
lib/Keepyourhead/database/Flashcard.rb

Instance Attribute Summary

Attributes inherited from BaseItemWithXml

#file, #node

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseItemWithXml

#database, #initialize, my_define_method, #objectFromNode, #parent

Methods included from XmlAccessor

addAttribute, addElementCData, addElementText, #xmlAccessorAttributeRead, #xmlAccessorAttributeWrite, #xmlAccessorElementCDataRead, #xmlAccessorElementCDataWrite, #xmlAccessorElementListCreate, #xmlAccessorElementListInsertAfter, #xmlAccessorElementListInsertBefore, #xmlAccessorElementListInsertFirst, #xmlAccessorElementListInsertLast, #xmlAccessorElementListNext, #xmlAccessorElementListPrevious, #xmlAccessorElementListRead, #xmlAccessorElementListRemove, #xmlAccessorElementTextRead, #xmlAccessorElementTextWrite

Methods inherited from BaseItem

#children, #next, #parent, #previous, #remove

Constructor Details

This class inherits a constructor from KeepYourHead::Database::BaseItemWithXml

Class Method Details

.createNode(file) ⇒ Object



107
108
109
110
111
112
# File 'lib/Keepyourhead/database/Flashcard.rb', line 107

def self.createNode( file )
  obj = Flashcard.new file, ::REXML::Element.new("flashcard")
  obj.name = "neue Flashcard" 
  obj.style = "latex"
  obj.node
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/Keepyourhead/database/Flashcard.rb', line 69

def active?
  nextCheck <= Time.now
end

#collectFlashcardsObject

some functions defined on all database entities for iteration



39
40
41
# File 'lib/Keepyourhead/database/Flashcard.rb', line 39

def collectFlashcards
  [self]
end

#collectionObject



82
83
84
85
86
87
88
# File 'lib/Keepyourhead/database/Flashcard.rb', line 82

def collection
  ret = self
  while ret and not ret.kind_of? Collection
    ret = ret.parent
  end
  ret
end

#compileImage(type, options = {}) ⇒ Object



77
78
79
80
# File 'lib/Keepyourhead/database/Flashcard.rb', line 77

def compileImage(type, options = {})
  styleInstance = file.style(self.style)
  compilation = styleInstance.createImage(type, self, options )
end

#content(type, options = {}) ⇒ Object



73
74
75
76
# File 'lib/Keepyourhead/database/Flashcard.rb', line 73

def content(type, options = {})
  styleInstance = file.style(self.style)
  styleInstance.content(type, self, options)
end

#countObject



43
44
45
# File 'lib/Keepyourhead/database/Flashcard.rb', line 43

def count
  1
end

#countActiveObject



46
47
48
# File 'lib/Keepyourhead/database/Flashcard.rb', line 46

def countActive
  active? ? 1 : 0
end

#countPassiveObject



49
50
51
# File 'lib/Keepyourhead/database/Flashcard.rb', line 49

def countPassive
  active? ? 0 : 1
end

#distributionObject



53
54
55
56
57
58
59
# File 'lib/Keepyourhead/database/Flashcard.rb', line 53

def distribution
  distribution = []

  distribution[self.level] = 1

  distribution
end

#removeStatisticsObject



61
62
63
64
# File 'lib/Keepyourhead/database/Flashcard.rb', line 61

def removeStatistics
  self.level = 0
  self.nextCheck = Time.new - 60
end

#topicObject



90
91
92
# File 'lib/Keepyourhead/database/Flashcard.rb', line 90

def topic
  parent && parent.class == Topic && parent
end

#topicNamesObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/Keepyourhead/database/Flashcard.rb', line 93

def topicNames
  topics = []

  n = topic
  while n do
    topics << n.name
    n = n.topic
  end

  topics = topics.reverse
  topics
end