Class: Zakuro::Parameter::Catalog::Range

Inherits:
Object
  • Object
show all
Defined in:
lib/zakuro/parameter/catalog/range.rb

Overview

Range 範囲(開始日-終了日)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash: {}) ⇒ Range

初期化

Parameters:

  • hash (Hash<Symbol, Object>) (defaults to: {})

    パラメータ

Options Hash (hash:):

  • :start (Symbol)

    開始日

  • :start (Symbol)

    終了日



29
30
31
32
# File 'lib/zakuro/parameter/catalog/range.rb', line 29

def initialize(hash: {})
  @start = hash[:start]
  @last = hash[:last]
end

Instance Attribute Details

#lastDate (readonly)

Returns 終了日.

Returns:

  • (Date)

    終了日



20
21
22
# File 'lib/zakuro/parameter/catalog/range.rb', line 20

def last
  @last
end

#startDate (readonly)

Returns 開始日.

Returns:

  • (Date)

    開始日



18
19
20
# File 'lib/zakuro/parameter/catalog/range.rb', line 18

def start
  @start
end

Class Method Details

.validate(hash:) ⇒ Array<Exception::Case::Preset>

検証する

Parameters:

  • hash (Hash<Symbol, Object>)

    パラメータ

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zakuro/parameter/catalog/range.rb', line 44

def validate(hash:)
  failed = []
  return failed unless hash

  unless hash.is_a?(Hash)
    failed.push(
      Exception::Case::Preset.new(
        hash.class,
        template: Exception::Case::Pattern::INVALID_RANGE_TYPE
      )
    )
    return failed
  end

  failed.concat(BasisDate.validate(date: hash[:start]))
  failed.concat(BasisDate.validate(date: hash[:last]))

  failed
end

Instance Method Details

#invalid?True, False

不正か

Returns:

  • (True)

    不正

  • (False)

    不正なし



71
72
73
74
75
76
77
# File 'lib/zakuro/parameter/catalog/range.rb', line 71

def invalid?
  return true unless @start

  return true unless @end

  false
end