Class: Hcp::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/hcp/filter.rb

Overview

One condition a list is narrowed by, as the parameters Housecall Pro takes it as.

Instance Method Summary collapse

Constructor Details

#initialize(bounds:, value:) ⇒ Filter

Returns a new instance of Filter.

Parameters:

  • bounds (Array<Symbol>)

    the parameter for each end of a range, or the single one.

  • value (Object)

    a range, or the one value to match.



6
7
8
9
# File 'lib/hcp/filter.rb', line 6

def initialize(bounds:, value:)
  @bounds = bounds
  @value = value
end

Instance Method Details

#paramsHash

Returns the parameters to send, without the end the caller left open.

Returns:

  • (Hash)

    the parameters to send, without the end the caller left open.



12
13
14
15
16
17
18
# File 'lib/hcp/filter.rb', line 12

def params
  return { @bounds.first => @value } unless @value.is_a? Range

  refuse
  low, high = @bounds
  { low => stamp(@value.begin), high => stamp(@value.end) }.compact
end