Module: ALaChart::HelperMethods
- Included in:
- InstanceMethods
- Defined in:
- lib/a_la_chart/a_la_chart.rb
Instance Method Summary collapse
- #data(the_case = nil) ⇒ Object
- #meta(the_case = nil) ⇒ Object
- #set_chart(chart_type) ⇒ Object
- #value(object, key, the_case = nil) ⇒ Object
Instance Method Details
#data(the_case = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/a_la_chart/a_la_chart.rb', line 14 def data(the_case=nil) if the_case.blank? (@data ||= {})['_'] ||= defined?(get_data) ? get_data : [] else (@data ||= {})[the_case] ||= respond_to?("get_data_#{the_case.to_s}") ? send("get_data_#{the_case.to_s}") : [] end end |
#meta(the_case = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/a_la_chart/a_la_chart.rb', line 4 def (the_case=nil) if the_case.blank? (@metadata ||= {})['_'] ||= defined?() ? : {} # @metadata ||= defined?(get_meta) ? get_meta : {} else (@metadata ||= {})[the_case] ||= respond_to?("get_meta_#{the_case.to_s}") ? send("get_meta_#{the_case.to_s}") : [] # @metadata ||= respond_to?("get_meta_#{the_case.to_s}") ? send("get_meta_#{the_case.to_s}") : [] end end |
#set_chart(chart_type) ⇒ Object
42 43 44 |
# File 'lib/a_la_chart/a_la_chart.rb', line 42 def set_chart(chart_type) send "set_chart_#{chart_type}" end |
#value(object, key, the_case = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/a_la_chart/a_la_chart.rb', line 22 def value(object, key, the_case=nil) return '' if object.blank? || key.blank? # if there is a meta map, use it. else try the key itself key_field = (the_case)[key] || key return '' if key_field.blank? if key_field.class == Proc # TODO: How to do this in the context of the controller? val = key_field.call(object) elsif key_field.class == Fixnum val = object[key_field] if object.respond_to?('[]') elsif object.class != Array val = object[key_field] if object.respond_to?('[]') val = (object.respond_to?(key_field) ? object.send(key_field) : nil) if val.nil? val end end |