Module: Zakuro::Operation::Validator::Types

Defined in:
lib/zakuro/operation/month/validator.rb

Overview

Types 型判定

Constant Summary collapse

EMPTY_STRING =
'-'
BOOLEANS =
%w[true false].freeze

Class Method Summary collapse

Class Method Details

.bool?(str: '') ⇒ True, False

booleanか

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    boolean

  • (False)

    非boolean



94
95
96
# File 'lib/zakuro/operation/month/validator.rb', line 94

def bool?(str: '')
  BOOLEANS.include?(str)
end

.empiable_bool?(str: '') ⇒ True, False

boolean(空許容)か

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    boolean

  • (False)

    非boolean



106
107
108
109
110
# File 'lib/zakuro/operation/month/validator.rb', line 106

def empiable_bool?(str: '')
  return true if str == EMPTY_STRING

  bool?(str: str)
end

.empiable_string?(str: '') ⇒ True, False

有効文字列(空文字許容)か

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    有効

  • (False)

    無効



48
49
50
51
52
# File 'lib/zakuro/operation/month/validator.rb', line 48

def empiable_string?(str: '')
  return false unless str

  str.is_a?(String)
end

.month_days?(str: '') ⇒ True, False

月差分か

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    有効

  • (False)

    無効



120
121
122
123
124
125
126
# File 'lib/zakuro/operation/month/validator.rb', line 120

def month_days?(str: '')
  return true if str == EMPTY_STRING

  return false unless str

  /^[大小]$/.match?(str)
end

.num?(str: '') ⇒ True, False

数値か

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    数値

  • (False)

    非数値



78
79
80
81
82
83
84
# File 'lib/zakuro/operation/month/validator.rb', line 78

def num?(str: '')
  return true if str == EMPTY_STRING

  return false unless str

  /^[-0-9]+$/.match?(str)
end

.positive?(str: '') ⇒ True, False

正数か

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    正数

  • (False)

    負数



62
63
64
65
66
67
68
# File 'lib/zakuro/operation/month/validator.rb', line 62

def positive?(str: '')
  return true if str == EMPTY_STRING

  return false unless str

  /^[0-9]+$/.match?(str)
end

.string?(str: '') ⇒ True, False

有効文字列か

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    有効

  • (False)

    無効



32
33
34
35
36
37
38
# File 'lib/zakuro/operation/month/validator.rb', line 32

def string?(str: '')
  return false if str == ''

  return false unless str

  str.is_a?(String)
end

.western_date?(str: '') ⇒ True, False

西暦日か

Parameters:

  • str (String) (defaults to: '')

    対象文字列

Returns:

  • (True)

    有効

  • (False)

    無効



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/zakuro/operation/month/validator.rb', line 136

def western_date?(str: '')
  return Western::Calendar.new if str == EMPTY_STRING

  # 1316-11-16/1317-4-13
  dates = str.split('/')
  dates.each do |date|
    return true if Western::Calendar.valid_date_text(text: date)
  end

  false
end