module MyChart::Type

Public Class Methods

concrete(type) click to toggle source
# File lib/my_chart/type.rb, line 10
def concrete type
  chart_class = detect{|klass| class_to_sym(klass) == type }
  raise Exception, "no such chart: #{type}" unless chart_class
  chart_class
end
each(&blk) click to toggle source
# File lib/my_chart/type.rb, line 16
def each &blk
  load_concrete_charts
  custom_charts.each &blk
end
each_sym(&blk) click to toggle source
# File lib/my_chart/type.rb, line 21
def each_sym &blk
  map{ |klass| class_to_sym klass }.each &blk
end
load_concrete_charts() click to toggle source
# File lib/my_chart/type.rb, line 25
def load_concrete_charts
  return if @loaded
  definitions.each do |c|
    class_eval File.read(c)
  end
  @loaded = true
end

Private Class Methods

basename(klass) click to toggle source
# File lib/my_chart/type.rb, line 39
def basename klass
  klass.name.split(/::/)[-1]
end
class_to_sym(klass) click to toggle source
# File lib/my_chart/type.rb, line 35
def class_to_sym klass
  basename(klass).anticapitalize.to_sym
end
custom_charts() click to toggle source
# File lib/my_chart/type.rb, line 48
def custom_charts
  self.constants.map do |const|
    const_get(const)
  end.select do |klass|
    klass != MyChart::Proto
  end
end
definitions() click to toggle source
# File lib/my_chart/type.rb, line 43
def definitions
  path = File.expand_path("../charts/*", __FILE__)
  Dir[path]
end