Class: Flock::QueryTerm

Inherits:
Object
  • Object
show all
Defined in:
lib/flock/operations/query_term.rb

Constant Summary collapse

STATES =

symbol => state_id map

Flock::Edges::EdgeState::VALUE_MAP.inject({}) do |states, (id, name)|
  states.update name.downcase.to_sym => id
end.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, graphs = nil) ⇒ QueryTerm

Returns a new instance of QueryTerm.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
# File 'lib/flock/operations/query_term.rb', line 10

def initialize(query, graphs = nil)
  raise ArgumentError if query.size < 3
  @graphs = graphs

  @source, @graph, @destination, @states = *query_args(query)
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



8
9
10
# File 'lib/flock/operations/query_term.rb', line 8

def destination
  @destination
end

#graphObject

Returns the value of attribute graph.



8
9
10
# File 'lib/flock/operations/query_term.rb', line 8

def graph
  @graph
end

#sourceObject

Returns the value of attribute source.



8
9
10
# File 'lib/flock/operations/query_term.rb', line 8

def source
  @source
end

#statesObject

Returns the value of attribute states.



8
9
10
# File 'lib/flock/operations/query_term.rb', line 8

def states
  @states
end

Instance Method Details

#==(other) ⇒ Object



44
45
46
47
48
49
# File 'lib/flock/operations/query_term.rb', line 44

def ==(other)
  self.source == other.source &&
    self.graph == other.graph &&
    self.destination == other.destination &&
    self.states == other.states
end

#forward?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/flock/operations/query_term.rb', line 17

def forward?
  @source.is_a? Numeric
end

#to_thriftObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/flock/operations/query_term.rb', line 25

def to_thrift
  term = Edges::QueryTerm.new
  term.graph_id = @graph
  term.state_ids = @states unless @states.nil? or @states.empty?
  term.is_forward = forward?

  source, destination =
    if term.is_forward
      [@source, @destination]
    else
      [@destination, @source]
    end

  term.source_id = source
  term.destination_ids = Array(destination).pack("Q*") if destination

  term
end

#unapplyObject



21
22
23
# File 'lib/flock/operations/query_term.rb', line 21

def unapply
  [@source, @graph, @destination, @states]
end