<commit_before>class Image < ActiveRecord::Base
  # Includes
  mount_uploader :asset, ImageUploader
  include RssRecordTouch

  # Before, after callbacks
  before_save :update_values

  # Default scopes, default values (e.g. self.per_page =)
  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def store_dir
    'public/uploads'
  end

  DEFAULT_QUERY = 'title_or_desc_or_tags_cache_or_place_or_album_title_cont'
  TITLE_MIN_FOR_SALE = 7
  TITLE_MIN = 4
  DESC_MIN_FOR_SALE = 30
  DESC_MIN = 15
  TAGS_MIN_FOR_SALE = 30
  TAGS_MIN = 10

  PER_PAGE = 25

  # Associations: belongs_to > has_one > has_many > has_and_belongs_to_many
  belongs_to :album

  # Validations: presence > by type > validates
  validates_presence_of :asset, :album, :title
  validates_numericality_of :flickr_photo_id, if: Proc.new { |i| i.flickr_photo_id.present? }

  # Other properties (e.g. accepts_nested_attributes_for)
  attr_accessible :asset, :asset_cache, :album_id, :title, :desc, :place, :date, :updated_at,
                  :published_at_checkbox, :tags, :tags_resolved, :flickr_photo_id, :flickr_comment_time,
                  :deviantart_link, :istockphoto_link, :shutterstock_link,
                  :is_for_sale, :image_width, :image_height
  attr_taggable :tags

  # Model dictionaries, state machine

  # Scopes
  default_scope order: 'images.published_at DESC, images.created_at DESC'

  scope :published, ->() { where('images.published_at IS NOT NULL') }

  scope :from_published_album, ->() { joins(:album).where('(albums.is_published = ? AND albums.is_upload_to_stock = ?)', true, true) }

  class << self
  end

  # Other model methods
  def to_param
    "#{self.id}-#{self.title.parameterize}"
  end

  def published_at_checkbox
    self.published_at.present?
  end

  def published_at_checkbox=(val)
    self.published_at = set_time(self.published_at, val)
  end

  def tags_resolved
    self.tags * ', '
  end

  def tags_resolved=(value)
    self.tags = value if value.present?
  end

  def render_data
    data = ''
    [self.desc, self.place, self.date.try(:strftime, '%Y')].each do |text|
      unless text.empty?
        data << '. ' if data.length > 0
        data << text
      end
    end
    data
  end

  # Private methods (for example: custom validators)
  private

  def update_values
    self.tags_cache = self.tags_resolved
  end

  def set_time(initial_value, checkbox_value)
    if checkbox_value == '1' && initial_value.blank?
      Time.now
    else
      (checkbox_value != '1') ? nil : initial_value
    end
  end

  protected

  def is_published?
    self.published_at.present?
  end

  def is_published_was
    i.published_at_was.blank?
  end
end<commit_msg>fixes in image private methods<commit_after>class Image < ActiveRecord::Base
  # Includes
  mount_uploader :asset, ImageUploader
  include RssRecordTouch

  # Before, after callbacks
  before_save :update_values

  # Default scopes, default values (e.g. self.per_page =)
  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def store_dir
    'public/uploads'
  end

  DEFAULT_QUERY = 'title_or_desc_or_tags_cache_or_place_or_album_title_cont'
  TITLE_MIN_FOR_SALE = 7
  TITLE_MIN = 4
  DESC_MIN_FOR_SALE = 30
  DESC_MIN = 15
  TAGS_MIN_FOR_SALE = 30
  TAGS_MIN = 10

  PER_PAGE = 25

  # Associations: belongs_to > has_one > has_many > has_and_belongs_to_many
  belongs_to :album

  # Validations: presence > by type > validates
  validates_presence_of :asset, :album, :title
  validates_numericality_of :flickr_photo_id, if: Proc.new { |i| i.flickr_photo_id.present? }

  # Other properties (e.g. accepts_nested_attributes_for)
  attr_accessible :asset, :asset_cache, :album_id, :title, :desc, :place, :date, :updated_at,
                  :published_at_checkbox, :tags, :tags_resolved, :flickr_photo_id, :flickr_comment_time,
                  :deviantart_link, :istockphoto_link, :shutterstock_link,
                  :is_for_sale, :image_width, :image_height
  attr_taggable :tags

  # Model dictionaries, state machine

  # Scopes
  default_scope order: 'images.published_at DESC, images.created_at DESC'

  scope :published, ->() { where('images.published_at IS NOT NULL') }

  scope :from_published_album, ->() { joins(:album).where('(albums.is_published = ? AND albums.is_upload_to_stock = ?)', true, true) }

  class << self
  end

  # Other model methods
  def to_param
    "#{self.id}-#{self.title.parameterize}"
  end

  def published_at_checkbox
    self.published_at.present?
  end

  def published_at_checkbox=(val)
    self.published_at = set_time(self.published_at, val)
  end

  def tags_resolved
    self.tags * ', '
  end

  def tags_resolved=(value)
    self.tags = value if value.present?
  end

  def render_data
    data = ''
    [self.desc, self.place, self.date.try(:strftime, '%Y')].each do |text|
      unless text.empty?
        data << '. ' if data.length > 0
        data << text
      end
    end
    data
  end

  # Private methods (for example: custom validators)
  private

  def update_values
    self.tags_cache = self.tags_resolved
  end

  def set_time(initial_value, checkbox_value)
    if checkbox_value == '1' && initial_value.blank?
      Time.now
    else
      (checkbox_value != '1') ? nil : initial_value
    end
  end

  protected

  def is_published?
    self.published_at.present?
  end

  def is_published_was
    self.published_at_was.blank?
  end
end
{'fraction_non_alphanumeric': 0.09552017771195853, 'fraction_numerical': 0.0055534987041836355, 'mean_word_length': 3.425061425061425, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3993863', 'n_tokens_mistral': 1968, 'n_tokens_neox': 1851, 'n_words': 419}