Class: Mu::Xtractr::Term

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mu/xtractr/term.rb,
lib/mu/xtractr/test/tc_term.rb

Overview

end

Defined Under Namespace

Classes: Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, json) ⇒ Term

:nodoc:



41
42
43
44
45
46
# File 'lib/mu/xtractr/term.rb', line 41

def initialize field, json # :nodoc:
    @field     = field
    @xtractr   = field.xtractr
    @value     = json['key']
    @frequency = json['value']
end

Instance Attribute Details

#fieldObject (readonly)

Return the field containing this term.



33
34
35
# File 'lib/mu/xtractr/term.rb', line 33

def field
  @field
end

#frequencyObject (readonly)

Return the (packet) frequency of this term.



39
40
41
# File 'lib/mu/xtractr/term.rb', line 39

def frequency
  @frequency
end

#valueObject (readonly)

Return the value of this term.



36
37
38
# File 'lib/mu/xtractr/term.rb', line 36

def value
  @value
end

#xtractrObject (readonly)

:nodoc:



30
31
32
# File 'lib/mu/xtractr/term.rb', line 30

def xtractr
  @xtractr
end

Instance Method Details

#each_packet(q = nil, &blk) ⇒ Object Also known as: each

Fetch each packet from the index that has this term in this field. If the optional q is specified, the search query is AND’d with the term’s own search query

field.term('mozilla').each { |pkt| ... }


52
53
54
55
56
# File 'lib/mu/xtractr/term.rb', line 52

def each_packet(q=nil, &blk) # :yields: packet
    _q = "#{field.name}:#{value}"
    _q << " #{q}" if q
    return Packets.new(xtractr, :q => _q).each(&blk)
end

#inspectObject

:nodoc:



66
67
68
# File 'lib/mu/xtractr/term.rb', line 66

def inspect # :nodoc:
    "#<term:#{field.name} #{value} #{frequency}>"
end

#packets(q = nil) ⇒ Object

Return an instance of Packets that serves as an iterator for all packets containing this term.



60
61
62
63
64
# File 'lib/mu/xtractr/term.rb', line 60

def packets q=nil
    _q = "#{field.name}:#{value}"
    _q << " #{q}" if q
    return Packets.new(xtractr, :q => _q)
end