Class: QueryFilter::Rules::SplitterRange::RangeParam

Inherits:
Object
  • Object
show all
Defined in:
lib/query_filter/rules/splitter_range.rb

Constant Summary collapse

SPLITTER =
/[;-]/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ RangeParam

Returns a new instance of RangeParam.



9
10
11
# File 'lib/query_filter/rules/splitter_range.rb', line 9

def initialize(value)
  @value = value
end

Instance Method Details

#itemsObject



21
22
23
# File 'lib/query_filter/rules/splitter_range.rb', line 21

def items
  @items ||= @value.split(SPLITTER).map(&:strip).map(&:to_i)
end

#rangeObject



17
18
19
# File 'lib/query_filter/rules/splitter_range.rb', line 17

def range
  ::Range.new(*items)
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/query_filter/rules/splitter_range.rb', line 13

def valid?
  @value.present? && items.size == 2
end