Class: Firepush::MessageTypes
- Inherits:
-
Object
- Object
- Firepush::MessageTypes
- Defined in:
- lib/firepush/message_types.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ MessageTypes
constructor
A new instance of MessageTypes.
- #message ⇒ Hash
- #valid? ⇒ Boolean
Constructor Details
#initialize(args) ⇒ MessageTypes
Returns a new instance of MessageTypes.
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
#types ⇒ Array<Firepush::MessageType::Base> (readonly)
5 6 7 |
# File 'lib/firepush/message_types.rb', line 5 def types @types end |
Instance Method Details
#message ⇒ Hash
20 21 22 23 24 25 |
# File 'lib/firepush/message_types.rb', line 20 def types.reduce({}) do |acc, type| acc[type.key] = type.value acc end end |
#valid? ⇒ Boolean
28 29 30 |
# File 'lib/firepush/message_types.rb', line 28 def valid? types.count > 0 && types.all?(&:valid?) end |