Class: Qiita::Elasticsearch::DateToken

Inherits:
Token
  • Object
show all
Includes:
Concerns::RangeOperandIncludable
Defined in:
lib/qiita/elasticsearch/date_token.rb

Constant Summary collapse

DATE_PATTERN =
Note:

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

/\A
  (?<year>\d{4})
  (?:
    -
    (?<month>\d{1,2})
    (?:
      -
      (?<day>\d{1,2})
    )?
  )?
\z/x

Constants included from Concerns::RangeOperandIncludable

Concerns::RangeOperandIncludable::RANGE_TERM_REGEXP

Instance Attribute Summary collapse

Attributes inherited from Token

#field_name, #term

Instance Method Summary collapse

Methods inherited from Token

#downcased?, #downcased_term, #filter?, #ignorable?, #initialize, #must?, #must_not?, #negative?, #or?, #positive?, #proper_cased_term, #quoted?, #to_s

Constructor Details

This class inherits a constructor from Qiita::Elasticsearch::Token

Instance Attribute Details

#time_zone=(value) ⇒ Object (writeonly)

Sets the attribute time_zone

Parameters:

  • value

    the value to set the attribute time_zone to.



24
25
26
# File 'lib/qiita/elasticsearch/date_token.rb', line 24

def time_zone=(value)
  @time_zone = value
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)

Raises:

  • (InvalidQuery)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/qiita/elasticsearch/date_token.rb', line 28

def to_hash
  if date_match
    if range_parameter
      {
        "range" => {
          @field_name => {
            range_parameter => range_query,
            "time_zone" => @time_zone,
          }.reject do |key, value|
            key == "time_zone" && value.nil?
          end,
        },
      }
    else
      {
        "range" => {
          @field_name => {
            "gte" => beginning_of_range.to_s,
            "lt" => end_of_range.to_s,
            "time_zone" => @time_zone,
          }.reject do |key, value|
            key == "time_zone" && value.nil?
          end,
        },
      }
    end
  else
    Nodes::NullNode.new.to_hash
  end
end