Sha256: 71d09baf2b686d11c17e4735f856a1ca7296d0ea0f5d960236ecc089ceb0cda2

Contents?: true

Size: 1.09 KB

Versions: 14

Compression:

Stored size: 1.09 KB

Contents

class PeakFlowUtils::GroupService
  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 = args.fetch(:handler)
    @id = args.fetch(:id)
    @data = args[:data] || {}
    raise "Invalid ID: #{@id}" if @id.blank?
  end

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

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

    translations_list
  end

  def to_param
    id
  end

  def name
    @data[:name].presence || id.presence
  end

  def to_s
    "<PeakFlowUtils::GroupService id=\"#{@id}\" name=\"#{name}\">"
  end

  def inspect
    to_s
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
peak_flow_utils-0.1.19 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.18 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.17 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.16 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.15 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.14 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.13 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.12 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.11 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.10 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.9 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.8 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.7 app/services/peak_flow_utils/group_service.rb
peak_flow_utils-0.1.6 app/services/peak_flow_utils/group_service.rb