Class: Firepush::MessageTypes

Inherits:
Object
  • Object
show all
Defined in:
lib/firepush/message_types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ MessageTypes

Returns a new instance of MessageTypes.

Parameters:

  • args (Hash)

Options Hash (args):

  • :notification (Hash)
  • :data (Hash)


10
11
12
13
14
15
16
17
# File 'lib/firepush/message_types.rb', line 10

def initialize(args)
  valid_types = MessageType::TYPES.reduce([]) do |acc, type|
    acc.push(type => args[type]) if args.key?(type)
    acc
  end

  @types = valid_types.map { |type| MessageType::Builder.build(type) }
end

Instance Attribute Details

#typesArray<Firepush::MessageType::Base> (readonly)

Returns:



5
6
7
# File 'lib/firepush/message_types.rb', line 5

def types
  @types
end

Instance Method Details

#messageHash

Returns:

  • (Hash)


20
21
22
23
24
25
# File 'lib/firepush/message_types.rb', line 20

def message
  types.reduce({}) do |acc, type|
    acc[type.key] = type.value
    acc
  end
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/firepush/message_types.rb', line 28

def valid?
  types.count > 0 && types.all?(&:valid?)
end