Skip to content

Instantly share code, notes, and snippets.

@gotmayonase
Created November 11, 2015 16:59
Show Gist options
  • Save gotmayonase/80b5c9025012e6078db0 to your computer and use it in GitHub Desktop.
Save gotmayonase/80b5c9025012e6078db0 to your computer and use it in GitHub Desktop.
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