Class: PXMyPortal::Payslip

Inherits:
Object
  • Object
show all
Defined in:
lib/pxmyportal/payslip.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year_month:, description:, key1:, key2:, key3:, directory: PXMyPortal::XDG::DOC_DIR) ⇒ Payslip

Returns a new instance of Payslip.



21
22
23
24
25
26
27
28
29
# File 'lib/pxmyportal/payslip.rb', line 21

def initialize(year_month:, description:, key1:, key2:, key3:,
               directory: PXMyPortal::XDG::DOC_DIR)
  @year_month  = year_month
  @description = description
  @key1        = key1
  @key2        = key2
  @key3        = key3
  @directory   = directory
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



19
20
21
# File 'lib/pxmyportal/payslip.rb', line 19

def description
  @description
end

#directoryObject (readonly)

Returns the value of attribute directory.



19
20
21
# File 'lib/pxmyportal/payslip.rb', line 19

def directory
  @directory
end

#year_monthObject (readonly)

Returns the value of attribute year_month.



19
20
21
# File 'lib/pxmyportal/payslip.rb', line 19

def year_month
  @year_month
end

Class Method Details

.from_row(row, directory: nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pxmyportal/payslip.rb', line 54

def self.from_row(row, directory: nil)
  row.xpath("./td") => [year_month, description, button]
  year_month.xpath(".//text()") => [year_month]
  description.xpath(".//text()") => [description]

  button.xpath(".//@onclick") => [listener]
  listener = listener.value

  keys = /\AOpenPdf\('(?<key1>\d+)','(?<key2>\d+)',(?<key3>\d+)\);\z/
  match = listener.match(keys) or raise Error, listener.inspect

  key1 = match[:key1]
  key2 = match[:key2]
  key3 = match[:key3]

  options = {}
  directory and options[:directory] = directory

  new(year_month: year_month.content,
      description: description.content,
      key1:, key2:, key3:,
      **options)
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
47
48
# File 'lib/pxmyportal/payslip.rb', line 44

def ==(other)
  other => Hash
  @year_month == other[:year_month] \
    && @description == other[:description]
end

#filenameObject



31
32
33
# File 'lib/pxmyportal/payslip.rb', line 31

def filename
  @filename ||= File.join(@directory, "#{@key1}-#{@key2}-#{@key3}.pdf")
end

#form_dataObject



35
36
37
# File 'lib/pxmyportal/payslip.rb', line 35

def form_data
  { key1: @key1, key2: @key2, key3: @key3 }
end

#metadataObject



39
40
41
42
# File 'lib/pxmyportal/payslip.rb', line 39

def 
  { year_month: @year_month, description: @description,
    filename: @filename }
end

#to_sObject



50
51
52
# File 'lib/pxmyportal/payslip.rb', line 50

def to_s
  "#<Payslip #{year_month.inspect} #{description.inspect}>"
end