Sha256: 67d7e24108abfa48603fe2a8bb0b174cc7addc6c71af9c9034d59326c6fd41cd

Contents?: true

Size: 846 Bytes

Versions: 6

Compression:

Stored size: 846 Bytes

Contents

module Lit
  class Locale < ActiveRecord::Base

    ## SCOPES
    scope :ordered, proc{ order('locale ASC') }
    scope :visible, proc{ where(:is_hidden=>false) }

    ## ASSOCIATIONS
    has_many :localizations, :dependent=>:destroy

    ## VALIDATIONS
    validates :locale,
              :presence=>true,
              :uniqueness=>true

    unless defined?(::ActionController::StrongParameters)
      ## ACCESSIBLE
      attr_accessible :locale
    end

    def to_s
      self.locale
    end

    def get_translated_percentage
      total = self.get_all_localizations_count
      total > 0 ? (self.get_changed_localizations_count * 100 / total) : 0
    end

    def get_changed_localizations_count
      self.localizations.changed.count(:id)
    end

    def get_all_localizations_count
      self.localizations.count(:id)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lit-0.2.4 app/models/lit/locale.rb
lit-0.2.3 app/models/lit/locale.rb
lit-0.2.2 app/models/lit/locale.rb
lit-0.2.1 app/models/lit/locale.rb
lit-0.2.0 app/models/lit/locale.rb
lit-0.1.0 app/models/lit/locale.rb