Class: Mikon::Index

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mikon/core/index.rb

Overview

Internal class for indexing

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ Index

Returns a new instance of Index.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mikon/core/index.rb', line 9

def initialize(source, options={})
  options = {
    name: nil
  }.merge(options)

  case
  when source.is_a?(Array)
    @data = Mikon::DArray.new(source)
  when source.is_a?(Mikon::DArray)
    @data = source
  else raise ArgumentError
  end

  @name = options[:name]
end

Instance Method Details

#sort_by(&block) ⇒ Object



25
26
27
28
# File 'lib/mikon/core/index.rb', line 25

def sort_by(&block)
  return self.to_enum(:sort_by) unless block_given?
  Mikon::Index.new(@data.sort_by(&block))
end