class Qiita::Elasticsearch::DateToken::AbsoluteDateExpression

Constants

PATTERN

@note Matches to “YYYY”, “YYYY-MM” and “YYYY-MM-DD”

Public Instance Methods

to_hash() click to toggle source
# File lib/qiita/elasticsearch/date_token.rb, line 53
def to_hash
  if @token.range_parameter
    range_block(@token.range_parameter => @token.range_query, "time_zone" => @token.time_zone)
  else
    range_block("gte" => beginning_of_range.to_s, "lt" => end_of_range.to_s, "time_zone" => @token.time_zone)
  end
end

Private Instance Methods

beginning_of_range() click to toggle source

@return [Date]

# File lib/qiita/elasticsearch/date_token.rb, line 87
def beginning_of_range
  @beginning_of_range ||=
    case
    when match[:day]
      Date.new(match[:year].to_i, match[:month].to_i, match[:day].to_i)
    when match[:month]
      Date.new(match[:year].to_i, match[:month].to_i)
    else
      Date.new(match[:year].to_i)
    end
end
end_of_range() click to toggle source

@return [Date]

# File lib/qiita/elasticsearch/date_token.rb, line 74
def end_of_range
  @end_of_range ||=
    case
    when match[:day]
      beginning_of_range + 1.day
    when match[:month]
      beginning_of_range + 1.month
    else
      beginning_of_range + 1.year
    end
end
range_block(field_block) click to toggle source
# File lib/qiita/elasticsearch/date_token.rb, line 63
def range_block(field_block)
  {
    "range" => {
      converted_field_name => field_block.reject do |key, value|
        key == "time_zone" && value.nil?
      end,
    }
  }
end