Module: TaxJp::SocialInsurances::Utils

Included in:
TaxJp::SocialInsurance
Defined in:
lib/tax_jp/social_insurances/utils.rb

Instance Method Summary collapse

Instance Method Details

#convert_to_date(value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tax_jp/social_insurances/utils.rb', line 3

def convert_to_date(value)
  ret = nil

  if value.is_a?(Date)
    ret = value.strftime('%Y-%m-%d')
  elsif value.is_a?(String)
    ret = value
  else
    raise TypeError.new(value.class)
  end

  ret
end

#convert_to_prefecture_code(value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/tax_jp/social_insurances/utils.rb', line 17

def convert_to_prefecture_code(value)
  ret = nil

  if value.is_a?(TaxJp::Prefecture)
    ret = value.code
  elsif value.to_s =~ /[0-9]{2}/
    ret = value.to_s
  else
    p = TaxJp::Prefecture.find_by_name(value.to_s)
    if p
      ret = p.code
    else
      raise TypeError.new(value.class)
    end
  end

  ret
end