Class: Array

Inherits:
Object show all
Defined in:
lib/clevic/cache_table.rb,
lib/clevic/extensions.rb

Overview

This is part of Array in case the programmer wants to use a simple array instead of a CacheTable.

Direct Known Subclasses

Clevic::CacheTable

Instance Method Summary collapse

Instance Method Details

#cached_at?(index) ⇒ Boolean

For use with CacheTable. Return true if something is cached, false otherwise

Returns:

  • (Boolean)


173
174
175
# File 'lib/clevic/cache_table.rb', line 173

def cached_at?( index )
  !at(index).nil?
end

#groupObject

group by ascending values



74
75
76
77
78
79
80
81
82
83
# File 'lib/clevic/extensions.rb', line 74

def group
  parts = []
  next_section = section
  if next_section.empty?
    parts
  else
    parts << section
    parts + self[section.size..-1].group
  end
end

#rangeObject



85
86
87
# File 'lib/clevic/extensions.rb', line 85

def range
  first..last
end

#searchObject



177
178
179
# File 'lib/clevic/cache_table.rb', line 177

def search
  raise "not implemented"
end

#sectionObject



63
64
65
66
67
68
69
70
71
# File 'lib/clevic/extensions.rb', line 63

def section
  return [] if empty?
  rv = [first]
  self[1..-1].each_with_index do |next_value, index|
    break if rv.last.succ != next_value
    rv << next_value
  end
  rv
end

#sparseObject



57
58
59
60
61
# File 'lib/clevic/extensions.rb', line 57

def sparse
  (first..last).map do |index|
    index if include?( index )
  end
end

#sparse_hashObject



51
52
53
54
55
# File 'lib/clevic/extensions.rb', line 51

def sparse_hash
  Hash[ *(first..last).map do |index|
    [index, include?( index ) ]
  end.flatten ]
end