Class: JLDrill::Counter
- Inherits:
-
Object
- Object
- JLDrill::Counter
- Defined in:
- lib/jldrill/model/Quiz/Counter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ranges ⇒ Object
readonly
Returns the value of attribute ranges.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #initializeTable ⇒ Object
- #levelString(level) ⇒ Object
- #makeRanges ⇒ Object
- #to_s ⇒ Object
-
#toDays(seconds) ⇒ Object
Returns the rounded number of days from seconds.
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
8 9 10 11 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 8 def initialize @ranges = makeRanges @table = initializeTable end |
Instance Attribute Details
#ranges ⇒ Object (readonly)
Returns the value of attribute ranges.
6 7 8 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 6 def ranges @ranges end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 6 def table @table end |
Class Method Details
.findRange(level) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 29 def Counter.findRange(level) low = Duration.new(0) high = Duration.new high.days = 5.0 1.upto(level) do low.assign(high) high.seconds = Schedule.backoff(low.seconds) end return low.seconds...high.seconds end |
.getLevel(item) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 40 def Counter.getLevel(item) level = 0 found = false while (level <= 6) && !found range = Counter.findRange(level) if item.schedule.durationWithin?(range) found = true else level += 1 end end return level end |
Instance Method Details
#initializeTable ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 13 def initializeTable retVal = [] 0.upto(7) do |level| retVal.push(0) end return retVal end |
#levelString(level) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 60 def levelString(level) if level == 0 return "Less than #{toDays(@ranges[0].end)} days" elsif level == 7 return "More than #{toDays(@ranges[6].end)} days" else return "#{toDays(@ranges[level].begin)} to #{toDays(@ranges[level].end)} days" end end |
#makeRanges ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 21 def makeRanges retVal = [] 0.upto(6) do |level| retVal.push(Counter.findRange(level)) end return retVal end |
#to_s ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/jldrill/model/Quiz/Counter.rb', line 70 def to_s retVal = "" 0.upto(7) do |i| retVal = retVal + levelString(i) + " #{@table[i]}\n" end return retVal end |