Class: Flock::QueryTerm
- Inherits:
-
Object
- Object
- Flock::QueryTerm
- 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
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#graph ⇒ Object
Returns the value of attribute graph.
-
#source ⇒ Object
Returns the value of attribute source.
-
#states ⇒ Object
Returns the value of attribute states.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #forward? ⇒ Boolean
-
#initialize(query, graphs = nil) ⇒ QueryTerm
constructor
A new instance of QueryTerm.
- #to_thrift ⇒ Object
- #unapply ⇒ Object
Constructor Details
#initialize(query, graphs = nil) ⇒ QueryTerm
Returns a new instance of QueryTerm.
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
#destination ⇒ Object
Returns the value of attribute destination.
8 9 10 |
# File 'lib/flock/operations/query_term.rb', line 8 def destination @destination end |
#graph ⇒ Object
Returns the value of attribute graph.
8 9 10 |
# File 'lib/flock/operations/query_term.rb', line 8 def graph @graph end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/flock/operations/query_term.rb', line 8 def source @source end |
#states ⇒ Object
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
17 18 19 |
# File 'lib/flock/operations/query_term.rb', line 17 def forward? @source.is_a? Numeric end |
#to_thrift ⇒ Object
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 |
#unapply ⇒ Object
21 22 23 |
# File 'lib/flock/operations/query_term.rb', line 21 def unapply [@source, @graph, @destination, @states] end |