OSDN Git Service

change form manifest
[pettanr/pettanr.git] / lib / validators / sync_vh_validator.rb
1 class SyncVhValidator < ActiveModel::EachValidator\r
2   def validate_each(record, attribute, value)\r
3     record.picture.boosts 'post'\r
4     if record.picture and record.picture.license_extend.sync_vh < 0\r
5       record.errors[attribute] << (options[:message] || I18n.t('activerecord.errors.messages.sync_vh')) unless sync?(record)\r
6     end\r
7   end\r
8   \r
9   def sync?(record)\r
10     r = record.width * 100 / record.height\r
11     r2 = record.picture.width * 100 / record.picture.height\r
12     (r >= r2 - 1) and (r <= r2 + 1)\r
13   end\r
14   \r
15 end\r
16 \r