Class: Pntfr::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/pntfr/notification.rb

Constant Summary collapse

FILE_EXTENSION_REGEXP =
/(\.[^\.]+)\z/

Instance Method Summary collapse

Constructor Details

#initialize(content, custom = nil) ⇒ Notification

Returns a new instance of Notification.



10
11
12
13
# File 'lib/pntfr/notification.rb', line 10

def initialize content, custom=nil
  @content= content
  @custom= custom
end

Instance Method Details

#remove_extension(filename) ⇒ Object



37
38
39
# File 'lib/pntfr/notification.rb', line 37

def remove_extension filename
  filename.gsub(FILE_EXTENSION_REGEXP, '')
end

#to_androidObject



28
29
30
31
32
33
34
35
36
# File 'lib/pntfr/notification.rb', line 28

def to_android
  data= {
    :title        => @content[:title],
    :description  => @content[:description],
  }
  data[:sound]= remove_extension(@content[:sound]) unless @content[:sound].nil?
  data[:custom]= @custom if @custom
  data
end

#to_iosObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pntfr/notification.rb', line 15

def to_ios
  alert= @content[:title]
  alert+= "\n#{@content[:description]}" if @content.key?(:description)
  sound= @content[:sound]
  badge= @content[:badge]
  badge= @content[:badge].to_i if badge
  n= {:alert => alert, :sound => 'default'}
  n[:sound]= sound if sound
  n[:badge]= badge if badge
  n.merge!({other: {custom: @custom}}) if @custom
  n
end