Class: MetaReports::Data

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Data.

Yields:

  • (_self)

Yield Parameters:



2
3
4
5
6
# File 'app/models/meta_reports/data.rb', line 2

def initialize
  @hash = {tables: {}}
  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



8
9
10
11
12
13
14
15
16
17
# File 'app/models/meta_reports/data.rb', line 8

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



19
20
21
# File 'app/models/meta_reports/data.rb', line 19

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

#[]=(key, value) ⇒ Object



23
24
25
# File 'app/models/meta_reports/data.rb', line 23

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

#tablesObject



27
28
29
# File 'app/models/meta_reports/data.rb', line 27

def tables
  @hash[:tables]
end

#to_hObject



31
32
33
# File 'app/models/meta_reports/data.rb', line 31

def to_h
  @hash
end