Class: CloudSesame::Query::AST::Literal

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_sesame/query/ast/literal.rb

Constant Summary collapse

SINGLE_QUATE =
Regexp.new(/\'/).freeze
ESCAPE_QUATE =
"\\'".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, value, options = {}) ⇒ Literal

Returns a new instance of Literal.



11
12
13
14
15
# File 'lib/cloud_sesame/query/ast/literal.rb', line 11

def initialize(field, value, options = {})
  @field = field
  @options = options
  @value = LazyObject.new { (options[:type] || Value).parse(value) } if value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



9
10
11
# File 'lib/cloud_sesame/query/ast/literal.rb', line 9

def value
  @value
end

Instance Method Details

#applied(included) ⇒ Object



22
23
24
# File 'lib/cloud_sesame/query/ast/literal.rb', line 22

def applied(included)
  { field: @field, value: @value, included: included } if @value
end

#as_fieldObject



26
27
28
# File 'lib/cloud_sesame/query/ast/literal.rb', line 26

def as_field
  @options[:as] || @field
end

#compile(detailed = false) ⇒ Object



30
31
32
# File 'lib/cloud_sesame/query/ast/literal.rb', line 30

def compile(detailed = false)
  (detailed ? detailed_format : standard_format) if @value
end

#is_for(field, options = {}) ⇒ Object



17
18
19
20
# File 'lib/cloud_sesame/query/ast/literal.rb', line 17

def is_for(field, options = {})
  @field = field
  @options.merge! options
end