Module: Transcribable::ClassMethods
- Defined in:
- lib/transcribable.rb
Instance Method Summary collapse
-
#assign!(user_id) ⇒ Object
Override this to write your own assigner By default, it picks a random filing that a user has not transcribed.
-
#set_verification_threshhold(lvl = 1) ⇒ Object
The number over which people must agree on every attribute to verify a transcription.
-
#skip_transcription(*args) ⇒ Object
Attributes that are potential reasons to skip a transcription.
- #skip_verification(*args) ⇒ Object
- #skipped_attrs ⇒ Object
- #transcribable(*args) ⇒ Object
- #transcribable?(_attr) ⇒ Boolean
- #verification_threshhold ⇒ Object
Instance Method Details
#assign!(user_id) ⇒ Object
Override this to write your own assigner By default, it picks a random filing that a user has not transcribed. If there’s nothing left for that user to do, it returns nil. This will get slower the more transcriptions you have, so it’ll be a good idea to index the filing_id (or whatever master table foreign key) column in your transcriptions table.
99 100 101 102 103 104 105 106 107 |
# File 'lib/transcribable.rb', line 99 def assign!(user_id) user_transcribed_filings = Transcription.where(:user_id => user_id).map {|q| q["#{self.table_name.downcase.singularize}_id".to_sym] }.uniq filings = self.where(:verified => [nil, false]) if user_transcribed_filings.length > 0 filings = filings.where("id NOT IN (?)", user_transcribed_filings) end pick = rand(filings.length - 1) filings.length > 0 ? filings[pick] : nil end |
#set_verification_threshhold(lvl = 1) ⇒ Object
The number over which people must agree on every attribute to verify a transcription
77 78 79 |
# File 'lib/transcribable.rb', line 77 def set_verification_threshhold(lvl = 1) @@verification_threshhold = lvl end |
#skip_transcription(*args) ⇒ Object
Attributes that are potential reasons to skip a transcription. If enough people agree to skip, the filing will be marked transcribed.
88 89 90 |
# File 'lib/transcribable.rb', line 88 def skip_transcription(*args) @@skippable = args end |
#skip_verification(*args) ⇒ Object
66 67 68 |
# File 'lib/transcribable.rb', line 66 def skip_verification(*args) @@skip_verification = args end |
#skipped_attrs ⇒ Object
70 71 72 73 |
# File 'lib/transcribable.rb', line 70 def skipped_attrs return [] unless defined? @@skip_verification @@skip_verification end |
#transcribable(*args) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/transcribable.rb', line 55 def transcribable(*args) args.each do |k| self.columns_hash[k.to_s].instance_variable_set("@transcribable", true) end include Transcribable::LocalInstanceMethods end |
#transcribable?(_attr) ⇒ Boolean
62 63 64 |
# File 'lib/transcribable.rb', line 62 def transcribable?(_attr) self.columns_hash[_attr].instance_variable_get("@transcribable") end |
#verification_threshhold ⇒ Object
81 82 83 |
# File 'lib/transcribable.rb', line 81 def verification_threshhold @@verification_threshhold end |