Class: Turn::BucketMap

Inherits:
Object
  • Object
show all
Defined in:
lib/turn/bucket_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(term) ⇒ BucketMap

Returns a new instance of BucketMap.



9
10
11
12
13
# File 'lib/turn/bucket_map.rb', line 9

def initialize(term)
  @term = term
  @buckets = []
  @count = 0
end

Instance Attribute Details

#bucketsObject

Returns the value of attribute buckets.



7
8
9
# File 'lib/turn/bucket_map.rb', line 7

def buckets
  @buckets
end

#countObject

Returns the value of attribute count.



7
8
9
# File 'lib/turn/bucket_map.rb', line 7

def count
  @count
end

Instance Method Details

#load(dc) ⇒ Object



15
16
17
# File 'lib/turn/bucket_map.rb', line 15

def load(dc)
  parse(@term.dump_bucket_map(dc))
end

#parse(map) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/turn/bucket_map.rb', line 19

def parse(map)
  map.each_with_index do |bucket, index|
    if /(?<id>\S+):\s+(?<value>\d+)/ =~ bucket
      @count = value.to_i
      @buckets[index] = id
    end
  end
end