Sha256: fde718804a2bace7c48f52ccf2e62fb291ec0ff6d6f618a9a852ca1a40c21751

Contents?: true

Size: 632 Bytes

Versions: 1

Compression:

Stored size: 632 Bytes

Contents

module Cavy
  class ItemGroup < ::ActiveRecord::Base

    attr_accessor :param_string

    has_many :cavy_items

    before_save :set_params
    validates :title, presence: true

    def type
      title.downcase.gsub(' ', '_')
    end

    def items
      Cavy::Item.where(item_group_id: id)
    end

    def items_with_key_value(key, value)
      item_group = Cavy::ItemGroup.find(id)
      item_group.items.where("data.#{key}" => value)
    end

    private

    def set_params
      unless param_string == '' or param_string == nil
        self.params = param_string.gsub(/[,][ ]*/, ',').split(',')
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cavy-0.1.0.beta1 app/models/cavy/item_group.rb