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, production_confirm_path),
cache_filename: "normal", row_xpath: normal_row_xpath)
BONUS =

Previously PAYSLIP_PAGE_PATH_BONUS.

new(path: BONUS_PATH, confirm_path: production_confirm_path,
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.



30
31
32
33
34
35
36
37
38
# File 'lib/pxmyportal/page.rb', line 30

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.



28
29
30
# File 'lib/pxmyportal/page.rb', line 28

def confirm_path
  @confirm_path
end

#pathObject (readonly)

Returns the value of attribute path.



28
29
30
# File 'lib/pxmyportal/page.rb', line 28

def path
  @path
end

Class Method Details

.from_path(path) ⇒ Object



79
80
81
# File 'lib/pxmyportal/page.rb', line 79

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

Instance Method Details

#cache_pathObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/pxmyportal/page.rb', line 40

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

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

#inspectObject



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

def inspect
  "#<Page #{@cache_filename}>"
end

#rows(source) ⇒ Object



51
52
53
# File 'lib/pxmyportal/page.rb', line 51

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