Class: Gravel::APNS::Notification::Localization
- Inherits:
-
Object
- Object
- Gravel::APNS::Notification::Localization
- Defined in:
- lib/gravel/apns/notification/localization.rb
Overview
This class can be used to localize part of a notification. You can set a notification’s title, subtitle or body attribute to an instance of this class to localize it.
Instance Attribute Summary collapse
-
#arguments ⇒ Array
Additional arguments to pass into the localizable string.
-
#key ⇒ String
readonly
The localization key as defined in your app’s localization file.
Instance Method Summary collapse
-
#arguments? ⇒ Boolean
Check if there are any additional arguments.
-
#initialize(key, *args) ⇒ Gravel::APNS::Notification::Localization
constructor
Create a new localization.
-
#payload(type) ⇒ Hash
Convert the localization into APNS payload components.
Constructor Details
#initialize(key, *args) ⇒ Gravel::APNS::Notification::Localization
Create a new localization.
27 28 29 30 31 32 33 34 |
# File 'lib/gravel/apns/notification/localization.rb', line 27 def initialize(key, *args) unless key.is_a?(String) raise 'The localization key must be a string.' end @key = key.to_s self.arguments = args end |
Instance Attribute Details
#arguments ⇒ Array
Additional arguments to pass into the localizable string.
19 20 21 |
# File 'lib/gravel/apns/notification/localization.rb', line 19 def arguments @arguments end |
#key ⇒ String (readonly)
The localization key as defined in your app’s localization file.
13 14 15 |
# File 'lib/gravel/apns/notification/localization.rb', line 13 def key @key end |
Instance Method Details
#arguments? ⇒ Boolean
Check if there are any additional arguments.
59 60 61 |
# File 'lib/gravel/apns/notification/localization.rb', line 59 def arguments? self.arguments && self.arguments.any? end |
#payload(type) ⇒ Hash
Convert the localization into APNS payload components.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gravel/apns/notification/localization.rb', line 68 def payload(type) components = Hash.new case type when :title components['title-loc-key'] = @key components['title-loc-args'] = self.arguments if arguments? when :subtitle components['subtitle-loc-key'] = @key components['subtitle-loc-args'] = self.arguments if arguments? when :body components['loc-key'] = @key components['loc-args'] = self.arguments if arguments? end components end |