Class: Ecoportal::API::GraphQL::Input::SearchConf::DateRange

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/ecoportal/api/graphql/input/search_conf.rb

Overview


Filter: date_filter (system date) / range_date_filter (register Date FIELD)

Instance Method Summary collapse

Methods included from Composable

#&, #|

Constructor Details

#initialize(key, gte: nil, lte: nil, time_zone: 'UTC') ⇒ DateRange

Returns a new instance of DateRange.



119
120
121
122
123
124
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 119

def initialize(key, gte: nil, lte: nil, time_zone: 'UTC')
  @key       = key.to_s
  @gte       = gte
  @lte       = lte
  @time_zone = time_zone
end

Instance Method Details

#substitute(subs) ⇒ Object



139
140
141
142
143
144
145
146
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 139

def substitute(subs)
  self.class.new(
    @key,
    gte:       subs.fetch(:gte, @gte),
    lte:       subs.fetch(:lte, @lte),
    time_zone: subs.fetch(:time_zone, @time_zone)
  )
end

#to_hObject

A register Date FIELD ('date.zXXXX') filters via range_date_filter on its nested membranes.date path; a system date (created_at/updated_at) uses date_filter (no path). Both share gte/lte/time_zone. See filter_contract_matrix.md (date rows) + backend Pages::RangeDateFilter.



130
131
132
133
134
135
136
137
# File 'lib/ecoportal/api/graphql/input/search_conf.rb', line 130

def to_h
  field  = MembranePath.field_key?(@key)
  params = { key: @key, time_zone: @time_zone }
  params[:path] = MembranePath.membrane_path_for(@key) if field
  params[:gte]  = @gte if @gte
  params[:lte]  = @lte if @lte
  { operation: field ? 'range_date_filter' : 'date_filter', params: params }
end