Class: MetaReports::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_reports/data.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Data

Returns a new instance of Data.

Yields:

  • (_self)

Yield Parameters:



3
4
5
6
7
8
# File 'lib/meta_reports/data.rb', line 3

def initialize
  @hash = {tables: {}}
  @id = rand(10000)
  yield self if block_given?
  self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



10
11
12
13
14
15
16
17
18
19
# File 'lib/meta_reports/data.rb', line 10

def method_missing(method, *args, &block)
  method_string = method.to_s
  if method_string =~ /^(.+)=$/
    @hash[$1.to_sym] = args.first
  elsif @hash[method.to_sym]
    @hash[method.to_sym]
  else
    @hash.send(method, *args)
  end
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/meta_reports/data.rb', line 21

def [](key)
  @hash[key]
end

#[]=(key, value) ⇒ Object



25
26
27
# File 'lib/meta_reports/data.rb', line 25

def []=(key, value)
  @hash[key] = value
end

#idObject



29
30
31
# File 'lib/meta_reports/data.rb', line 29

def id
  @hash[:id] || @hash[:title].to_s.downcase.gsub(/[^a-z]/,'_') || @id
end

#tablesObject



33
34
35
# File 'lib/meta_reports/data.rb', line 33

def tables
  @hash[:tables]
end

#tables=(value) ⇒ Object



37
38
39
# File 'lib/meta_reports/data.rb', line 37

def tables=(value)
  @hash[:tables] = value
end

#to_hObject



41
42
43
# File 'lib/meta_reports/data.rb', line 41

def to_h
  @hash
end