Module: Bmg::Factory

Included in:
Bmg, Relation
Defined in:
lib/bmg/support/factory.rb

Instance Method Summary collapse

Instance Method Details

#csv(path, options = {}, type = Type::ANY) ⇒ Object



25
26
27
# File 'lib/bmg/support/factory.rb', line 25

def csv(path, options = {}, type = Type::ANY)
  Reader::Csv.new(type, path, options).spied(Bmg.main_spy)
end

#empty(type = Type::ANY) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
# File 'lib/bmg/support/factory.rb', line 3

def empty(type = Type::ANY)
  raise ArgumentError, "Missing type" if type.nil?
  Relation::Empty.new(type)
end

#excel(*args, &bl) ⇒ Object



49
50
51
# File 'lib/bmg/support/factory.rb', line 49

def excel(*args, &bl)
  excel_file(*args, &bl)
end

#excel_file(path, options = {}, type = Type::ANY) ⇒ Object



45
46
47
# File 'lib/bmg/support/factory.rb', line 45

def excel_file(path, options = {}, type = Type::ANY)
  Reader::Excel.new(type, path, options).spied(Bmg.main_spy)
end

#generate(from, to, options = {}) ⇒ Object



16
17
18
19
# File 'lib/bmg/support/factory.rb', line 16

def generate(from, to, options = {})
  type = Type::ANY.with_attrlist([options[:as] || Operator::Generator::DEFAULT_OPTIONS[:as]])
  Operator::Generator.new(type, from, to, options)
end

#in_memory(enumerable, type = Type::ANY) ⇒ Object



12
13
14
# File 'lib/bmg/support/factory.rb', line 12

def in_memory(enumerable, type = Type::ANY)
  Relation::InMemory.new(type, enumerable).spied(Bmg.main_spy)
end

#json(*args, &bl) ⇒ Object



33
34
35
# File 'lib/bmg/support/factory.rb', line 33

def json(*args, &bl)
  json_file(*args, &bl)
end

#json_file(path, options = {}, type = Type::ANY) ⇒ Object



29
30
31
# File 'lib/bmg/support/factory.rb', line 29

def json_file(path, options = {}, type = Type::ANY)
  in_memory(path.load.map{|tuple| TupleAlgebra.symbolize_keys(tuple) })
end

#mutable(enumerable, type = Type::ANY) ⇒ Object



8
9
10
# File 'lib/bmg/support/factory.rb', line 8

def mutable(enumerable, type = Type::ANY)
  Relation::InMemory::Mutable.new(type, enumerable).spied(Bmg.main_spy)
end

#text_file(path, options = {}, type = Type::ANY) ⇒ Object



21
22
23
# File 'lib/bmg/support/factory.rb', line 21

def text_file(path, options = {}, type = Type::ANY)
  Reader::TextFile.new(type, path, options).spied(Bmg.main_spy)
end

#yaml(*args, &bl) ⇒ Object



41
42
43
# File 'lib/bmg/support/factory.rb', line 41

def yaml(*args, &bl)
  yaml_file(*args, &bl)
end

#yaml_file(path, options = {}, type = Type::ANY) ⇒ Object



37
38
39
# File 'lib/bmg/support/factory.rb', line 37

def yaml_file(path, options = {}, type = Type::ANY)
  in_memory(path.load.map{|tuple| TupleAlgebra.symbolize_keys(tuple) })
end