Class: GoodData::LCM2::SmartHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/gooddata/lcm/lcm2.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object



31
32
33
# File 'lib/gooddata/lcm/lcm2.rb', line 31

def method_missing(name, *_args)
  data(name)
end

Instance Method Details

#[](variable) ⇒ Object



35
36
37
# File 'lib/gooddata/lcm/lcm2.rb', line 35

def [](variable)
  data(variable)
end

#check_specification(variable) ⇒ Object



47
48
49
50
51
52
# File 'lib/gooddata/lcm/lcm2.rb', line 47

def check_specification(variable)
  if @specification && !@specification[variable.to_sym] && !@specification[variable.to_s] \
                    && !@specification[variable.to_s.downcase.to_sym] && !@specification[variable.to_s.downcase]
    fail "Param #{variable} is not defined in the specification"
  end
end

#clear_filtersObject



39
40
41
# File 'lib/gooddata/lcm/lcm2.rb', line 39

def clear_filters
  @specification = nil
end

#data(variable) ⇒ Object



54
55
56
57
# File 'lib/gooddata/lcm/lcm2.rb', line 54

def data(variable)
  check_specification(variable)
  fetch(keys.find { |k| k.to_s.downcase.to_sym == variable.to_s.downcase.to_sym }, nil)
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
# File 'lib/gooddata/lcm/lcm2.rb', line 59

def key?(key)
  return true if super

  keys.each do |k|
    return true if k.to_s.downcase.to_sym == key.to_s.downcase.to_sym
  end

  false
end

#respond_to_missing?(name, *_args) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
# File 'lib/gooddata/lcm/lcm2.rb', line 69

def respond_to_missing?(name, *_args)
  key = name.to_s.downcase.to_sym
  key?(key)
end

#setup_filters(filter) ⇒ Object



43
44
45
# File 'lib/gooddata/lcm/lcm2.rb', line 43

def setup_filters(filter)
  @specification = filter.to_hash
end