Sha256: 135cd1b48b3178566b1b6f82abf4ed7913764678ed14fa5e8a0f7019d3c7e38f

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

class AwesomeTranslations::Group
  attr_reader :handler, :id, :data

  def self.find_by_handler_and_id(handler, id)
    handler.groups.each do |group|
      return group if group.id == id.to_s
    end

    raise ActiveRecord::RecordNotFound, "Group not found by handler and ID: '#{handler.name}', '#{id}'."
  end

  def initialize(args)
    @handler, @id, @data = args[:handler], args[:id], args[:data]
  end

  def translations(args = {})
    translations_list = @handler.translations_for_group(self)

    args.each do |key, value|
      if key == :finished
        translations_list = translations_list.select { |translation| translation.finished? } if value
      elsif key == :unfinished
        translations_list = translations_list.select { |translation| translation.unfinished? } if value
      else
        raise "Unknown key: #{key}"
      end
    end

    return translations_list
  end

  def translations_count(args = {})
    count = 0
    translations(args).each { count += 1 }
    return count
  end

  def to_param
    id
  end

  def param_key
    id
  end

  def name
    if @data && @data[:name].present?
      return @data[:name].presence
    end

    return id
  end

  def to_s
    "<AwesomeTranslations::Group id=\"#{@id}\" name=\"#{@name}\">"
  end

  def inspect
    to_s
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
awesome_translations-0.0.17 app/models/awesome_translations/group.rb
awesome_translations-0.0.16 app/models/awesome_translations/group.rb
awesome_translations-0.0.15 app/models/awesome_translations/group.rb
awesome_translations-0.0.14 app/models/awesome_translations/group.rb
awesome_translations-0.0.13 app/models/awesome_translations/group.rb
awesome_translations-0.0.12 app/models/awesome_translations/group.rb
awesome_translations-0.0.10 app/models/awesome_translations/group.rb
awesome_translations-0.0.9 app/models/awesome_translations/group.rb
awesome_translations-0.0.8 app/models/awesome_translations/group.rb
awesome_translations-0.0.7 app/models/awesome_translations/group.rb
awesome_translations-0.0.6 app/models/awesome_translations/group.rb
awesome_translations-0.0.5 app/models/awesome_translations/group.rb
awesome_translations-0.0.4 app/models/awesome_translations/group.rb
awesome_translations-0.0.3 app/models/awesome_translations/group.rb