Sha256: 4b95b26d05b6c02cf77b903d125edbf46699aa36ecbb2665d56470e5023e73d5

Contents?: true

Size: 796 Bytes

Versions: 5

Compression:

Stored size: 796 Bytes

Contents

module Workarea
  module MailChimp
    class Group
      include ApplicationDocument

      field :_id, type: String
      field :name, type: String
      field :interests, type: Hash

      embedded_in :user, class_name: "Workarea::User"

      validate :id_or_name

      def self.email_interests
        MailChimp.gateway.get_default_list_interests.first
      end

      def to_hash
        [_id, name, interests].hash
      end

      def to_s
        "#{name} (#{id}) - #{interests}"
      end

      def ==(other)
        self.name == other[:name] && self.interests == other[:interests]
      end

      private

        def id_or_name
          unless id.present? || name.present?
            self.errors[:base] << "An ID or Name is Required."
          end
        end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
workarea-mail_chimp-3.1.0 app/models/workarea/mail_chimp/group.rb
workarea-mail_chimp-3.0.5 app/models/workarea/mail_chimp/group.rb
workarea-mail_chimp-3.0.4 app/models/workarea/mail_chimp/group.rb
workarea-mail_chimp-3.0.3 app/models/workarea/mail_chimp/group.rb
workarea-mail_chimp-3.0.2 app/models/workarea/mail_chimp/group.rb