Class: PXMyPortal::Page

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

Overview

Previously @phase.

Constant Summary collapse

BASEPATH =
"/pmpwps/"
CLIENT_BASEPATH =
File.join(BASEPATH, "pc/")
SAMPLE_PATH =
File.join(CLIENT_BASEPATH, "SalaryPayslipSample")
NORMAL_PATH =
File.join(CLIENT_BASEPATH, "SalaryPayslip")
BONUS_PATH =
File.join(CLIENT_BASEPATH, "BonusPayslip")
SAMPLE =

Previously PAYSLIP_PAGE_PATH_SAMPLE.

new(
path: SAMPLE_PATH,
confirm_path: File.join(CLIENT_BASEPATH, "ConfirmSamplePDFFrame"),
cache_filename: "sample", row_xpath: normal_row_xpath)
NORMAL =

Previously PAYSLIP_PAGE_PATH_NORMAL.

new(path: NORMAL_PATH,
confirm_path: File.join(CLIENT_BASEPATH, "ConfirmPDFFrame"),
cache_filename: "normal", row_xpath: normal_row_xpath)
BONUS =

Previously PAYSLIP_PAGE_PATH_BONUS.

new(path: BONUS_PATH, confirm_path: :TODO,
cache_filename: "bonus",
row_xpath: "//*[@id='ContentPlaceHolder1_BonusPayslipGridView']//tr")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, confirm_path:, cache_filename:, row_xpath:) ⇒ Page

Returns a new instance of Page.



12
13
14
15
16
17
18
19
20
# File 'lib/pxmyportal/page.rb', line 12

def initialize(path:, confirm_path:, cache_filename:, row_xpath:)
  @path = path

  # Previously confirm_pdf_frame_path.
  @confirm_path = confirm_path

  @cache_filename = cache_filename
  @row_xpath = row_xpath
end

Instance Attribute Details

#confirm_pathObject (readonly)

Returns the value of attribute confirm_path.



10
11
12
# File 'lib/pxmyportal/page.rb', line 10

def confirm_path
  @confirm_path
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/pxmyportal/page.rb', line 10

def path
  @path
end

Class Method Details

.from_path(path) ⇒ Object



55
56
57
# File 'lib/pxmyportal/page.rb', line 55

def self.from_path(path)
  { SAMPLE_PATH => SAMPLE, NORMAL_PATH => NORMAL, BONUS_PATH => NORMAL }[path]
end

Instance Method Details

#cache_pathObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/pxmyportal/page.rb', line 22

def cache_path
  @cache_path and return @cache_path
  @cache_path = File.join(PXMyPortal::XDG::CACHE_DIR, "debug", "page", "#{@cache_filename}.html")

  dir = File.dirname(@cache_path)
  unless Dir.exist?(dir)
    FileUtils.mkdir_p(dir)
  end
  @cache_path
end

#rows(source) ⇒ Object



33
34
35
# File 'lib/pxmyportal/page.rb', line 33

def rows(source)
  Nokogiri::HTML(source).xpath(@row_xpath)
end