Created
November 11, 2015 16:59
-
-
Save gotmayonase/80b5c9025012e6078db0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Segment < ActiveRecord::Base | |
extend ActsAsTree::TreeView | |
extend ActsAsTree::TreeWalker | |
belongs_to :course | |
belongs_to :section_type | |
has_and_belongs_to_many :chunks, join_table: 'chunks_segments' | |
acts_as_tree order: 'rank' | |
def word_count | |
@word_count ||= chunks.map(&:markup).join("\n").scan(/[\w-]+/).size | |
end | |
def required_time | |
(word_count / course.reading_speed.to_f * 60.0).round | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment