Class: LucaSalary::Base

Inherits:
LucaRecord::Base
  • Object
show all
Defined in:
lib/luca_salary/base.rb

Direct Known Subclasses

Monthly

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date = nil) ⇒ Base

Returns a new instance of Base.



15
16
17
18
# File 'lib/luca_salary/base.rb', line 15

def initialize(date = nil)
  @date = date.nil? ? Date.today : Date.parse(date)
  @dict = load_dict
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/luca_salary/base.rb', line 12

def config
  @config
end

#dictObject (readonly)

Returns the value of attribute dict.



12
13
14
# File 'lib/luca_salary/base.rb', line 12

def dict
  @dict
end

#pjdirObject (readonly)

Returns the value of attribute pjdir.



12
13
14
# File 'lib/luca_salary/base.rb', line 12

def pjdir
  @pjdir
end

Class Method Details

.sum_code(obj, code, exclude = nil) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/luca_salary/base.rb', line 46

def self.sum_code(obj, code, exclude = nil)
  target = obj.select { |k, _v| /^#{code}[0-9A-Fa-f]{,3}$/.match(k) }
  target = target
             .reject { |_k, v| v.nil? }
             .reject { |k, _v| exclude&.include?(k) }
  target.values.inject(:+) || 0
end

Instance Method Details

#amount_by_code(obj) ⇒ Object

Subtotal each items.

1

Base salary or wages.

2

Deduction directly related to work payment, including tax, insurance, pension and so on.

3

Deduction for miscellaneous reasons.

4

Addition for miscellaneous reasons.

5

Net payment amount.



36
37
38
39
40
41
42
43
44
# File 'lib/luca_salary/base.rb', line 36

def amount_by_code(obj)
  {}.tap do |h|
    (1..4).each do |n|
      code = n.to_s
      h[code] = self.class.sum_code(obj, code)
    end
    h['5'] = h['1'] - h['2'] - h['3'] + h['4']
  end
end

#select_code(dat, code) ⇒ Object



20
21
22
# File 'lib/luca_salary/base.rb', line 20

def select_code(dat, code)
  dat.filter { |k, _v| /^#{code}[0-9A-Fa-f]{,3}$/.match(k.to_s) }
end