Module: Transcribable::LocalInstanceMethods
- Defined in:
- lib/transcribable.rb
Instance Method Summary collapse
- #dc_slug ⇒ Object
-
#verify! ⇒ Object
Override this to create your own verifier.
Instance Method Details
#dc_slug ⇒ Object
153 154 155 |
# File 'lib/transcribable.rb', line 153 def dc_slug url.split(/\//)[-1] end |
#verify! ⇒ Object
Override this to create your own verifier. By default, all “transcribable” attributes need to be agreed on by @@verification_threshhold people.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/transcribable.rb', line 114 def verify! chosen = {} attributes = Transcribable.transcribable_attrs.keys.reject do |k| self.class.skipped_attrs.include?(k.to_sym) end Rails.logger.info("== Verifying #{attributes.join(", ")}") aggregate = transcriptions.reduce({}) do |memo, it| attributes.each do |attribute| memo[attribute] = memo[attribute] ? memo[attribute] : {} memo[attribute][it.instance_values['attributes'][attribute].to_s.upcase] = memo[attribute][it.instance_values['attributes'][attribute].to_s.upcase] ? memo[attribute][it.instance_values['attributes'][attribute].to_s.upcase] + 1 : 1 end memo end aggregate.each do |attribute, answers| answers.each do |answer, answer_ct| if answer_ct > self.class.verification_threshhold chosen[attribute] = answers.each.max_by {|k,v| v}.first end end end if chosen.keys.length == attributes.length attributes.each do |a| self[a] = chosen[a] end self.verified = true self.save Rails.logger.info("== Verified #{self.url}") else Rails.logger.info("== Not verified: #{self.url}") end end |