Class: ApraService::Notification
- Inherits:
-
Object
- Object
- ApraService::Notification
- Defined in:
- lib/apralib/notification.rb
Constant Summary collapse
- NON_NILLABLE_KEYS =
i[purpose expense_amount grant_date granted_to_group work_duration_months work_duration_days work_duration_years grantee amount ignore_work_duration].freeze
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#expense_amount ⇒ Object
Returns the value of attribute expense_amount.
-
#expense_description ⇒ Object
Returns the value of attribute expense_description.
-
#grant_date ⇒ Object
Returns the value of attribute grant_date.
-
#granted_to_group ⇒ Object
Returns the value of attribute granted_to_group.
-
#grantee ⇒ Object
Returns the value of attribute grantee.
-
#ignore_work_duration ⇒ Object
Returns the value of attribute ignore_work_duration.
-
#purpose ⇒ Object
Returns the value of attribute purpose.
-
#purpose_description ⇒ Object
Returns the value of attribute purpose_description.
-
#reference ⇒ Object
Returns the value of attribute reference.
-
#work_duration_days ⇒ Object
Returns the value of attribute work_duration_days.
-
#work_duration_months ⇒ Object
Returns the value of attribute work_duration_months.
-
#work_duration_years ⇒ Object
Returns the value of attribute work_duration_years.
-
#work_end_date ⇒ Object
Returns the value of attribute work_end_date.
-
#work_start_date ⇒ Object
Returns the value of attribute work_start_date.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Notification
constructor
A new instance of Notification.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ Notification
Returns a new instance of Notification.
14 15 16 17 18 19 20 21 |
# File 'lib/apralib/notification.rb', line 14 def initialize @ignore_work_duration = false @granted_to_group = false @work_duration_days = 0 @work_duration_months = 0 @work_duration_years = 0 @expense_amount = 0 end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def amount @amount end |
#expense_amount ⇒ Object
Returns the value of attribute expense_amount.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def expense_amount @expense_amount end |
#expense_description ⇒ Object
Returns the value of attribute expense_description.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def expense_description @expense_description end |
#grant_date ⇒ Object
Returns the value of attribute grant_date.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def grant_date @grant_date end |
#granted_to_group ⇒ Object
Returns the value of attribute granted_to_group.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def granted_to_group @granted_to_group end |
#grantee ⇒ Object
Returns the value of attribute grantee.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def grantee @grantee end |
#ignore_work_duration ⇒ Object
Returns the value of attribute ignore_work_duration.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def ignore_work_duration @ignore_work_duration end |
#purpose ⇒ Object
Returns the value of attribute purpose.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def purpose @purpose end |
#purpose_description ⇒ Object
Returns the value of attribute purpose_description.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def purpose_description @purpose_description end |
#reference ⇒ Object
Returns the value of attribute reference.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def reference @reference end |
#work_duration_days ⇒ Object
Returns the value of attribute work_duration_days.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def work_duration_days @work_duration_days end |
#work_duration_months ⇒ Object
Returns the value of attribute work_duration_months.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def work_duration_months @work_duration_months end |
#work_duration_years ⇒ Object
Returns the value of attribute work_duration_years.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def work_duration_years @work_duration_years end |
#work_end_date ⇒ Object
Returns the value of attribute work_end_date.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def work_end_date @work_end_date end |
#work_start_date ⇒ Object
Returns the value of attribute work_start_date.
5 6 7 |
# File 'lib/apralib/notification.rb', line 5 def work_start_date @work_start_date end |
Class Method Details
.from_hash(hash) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/apralib/notification.rb', line 55 def self.from_hash(hash) notification = Notification.new notification.purpose = hash[:kayttotarkoitus] notification.purpose_description = hash[:kayttotarkoitustarkenne] notification.expense_amount = hash[:kuluosuusrahamaara] notification.expense_description = hash[:kuluosuusteksti] notification.grant_date = hash[:myontopaatoksen_antopvm] notification.granted_to_group = hash[:onko_myonnetty_tyoryhmalle] notification.amount = hash[:rahamaara] notification.grantee = Grantee.from_hash(hash[:saajatiedot]) notification.work_duration_months = hash[:tyon_kesto_kuukausia] notification.work_duration_days = hash[:tyon_kesto_paivia] notification.work_duration_years = hash[:tyon_kesto_vuosia] notification.ignore_work_duration = hash[:tyonkestoeikantaa] notification.work_start_date = hash[:tyoskentelyn_alkamispvm] notification.work_end_date = hash[:tyoskentelyn_paattymispvm] notification.reference = hash[:viite] notification end |
Instance Method Details
#to_hash ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/apralib/notification.rb', line 23 def to_hash NON_NILLABLE_KEYS.each do |key| raise "Variable #{key} cannot be nil" if instance_variable_get("@#{key}").nil? end result = {} result[:kayttotarkoitus] = purpose result[:kayttotarkoitustarkenne] = purpose_description if purpose_description result[:kuluosuusrahamaara] = expense_amount result[:kuluosuusteksti] = expense_description if expense_description result[:myontopaatoksen_antopvm] = grant_date.rfc3339 result[:onko_myonnetty_tyoryhmalle] = granted_to_group result[:rahamaara] = amount result[:saajatiedot] = grantee.to_hash result[:sisaltaako_kuluja] = expense_amount.positive? if ignore_work_duration result[:tyon_kesto_kuukausia] = 0 result[:tyon_kesto_paivia] = 0 result[:tyon_kesto_vuosia] = 0 else result[:tyon_kesto_kuukausia] = work_duration_months result[:tyon_kesto_paivia] = work_duration_days result[:tyon_kesto_vuosia] = work_duration_years end result[:tyonkestoeikantaa] = ignore_work_duration result[:tyoskentelyn_alkamispvm] = work_start_date.rfc3339 if work_start_date result[:tyoskentelyn_paattymispvm] = work_end_date.rfc3339 if work_end_date result[:viite] = reference result end |