Class: Lionel::ExportBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/lionel/export_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/lionel/export_builder.rb', line 25

def method_missing(sym, *args, &block)
  column_name = sym.to_s.upcase
  if column_name =~ /\A[A-Z]+\z/
    columns[sym.to_s.upcase] = block_given? ? block : lambda { args.first }
  else
    raise ColumnNameError.new("Method '#{sym}' does not represent a valid Google Spreadsheet column name")
  end
end

Class Method Details

.build(&block) ⇒ Object



4
5
6
# File 'lib/lionel/export_builder.rb', line 4

def self.build(&block)
  new.configure(&block)
end

.defaultObject



8
9
10
11
12
13
14
# File 'lib/lionel/export_builder.rb', line 8

def self.default
  build do
    A { id }
    B { name }
    C { url }
  end
end

Instance Method Details

#columnsObject



21
22
23
# File 'lib/lionel/export_builder.rb', line 21

def columns
  @columns ||= {}
end

#configure(&block) ⇒ Object



16
17
18
19
# File 'lib/lionel/export_builder.rb', line 16

def configure(&block)
  instance_eval(&block)
  self
end