Module: Ambling::Base

Included in:
Column::Settings, Column::Settings::Axes, Column::Settings::Axes::Category, Column::Settings::Axes::Value, Column::Settings::Background, Column::Settings::Balloon, Column::Settings::Column, Column::Settings::ContextMenu, Column::Settings::ContextMenu::DefaultItems, Column::Settings::ErrorMessages, Column::Settings::ExportAsImage, Column::Settings::Graphs, Column::Settings::Graphs::Graph, Column::Settings::Grid, Column::Settings::Grid::Category, Column::Settings::Grid::Value, Column::Settings::Guides, Column::Settings::Guides::Guide, Column::Settings::Labels, Column::Settings::Labels::Label, Column::Settings::Legend, Column::Settings::Legend::Key, Column::Settings::Line, Column::Settings::PlotArea, Column::Settings::PlotArea::Margins, Column::Settings::Strings, Column::Settings::Values, Column::Settings::Values::Category, Column::Settings::Values::Value, Line::Settings, Line::Settings::Axes, Line::Settings::Axes::X, Line::Settings::Axes::YLeft, Line::Settings::Axes::YRight, Line::Settings::Background, Line::Settings::Balloon, Line::Settings::ContextMenu, Line::Settings::ContextMenu::DefaultItems, Line::Settings::ErrorMessages, Line::Settings::ExportAsImage, Line::Settings::Graphs, Line::Settings::Graphs::Graph, Line::Settings::Grid, Line::Settings::Grid::X, Line::Settings::Grid::YLeft, Line::Settings::Grid::YRight, Line::Settings::Guides, Line::Settings::Guides::Guide, Line::Settings::Help, Line::Settings::Help::Balloon, Line::Settings::Help::Button, Line::Settings::Indicator, Line::Settings::Labels, Line::Settings::Labels::Label, Line::Settings::Legend, Line::Settings::Legend::Key, Line::Settings::Legend::Values, Line::Settings::PlotArea, Line::Settings::PlotArea::Margins, Line::Settings::Scroller, Line::Settings::Strings, Line::Settings::Values, Line::Settings::Values::X, Line::Settings::Values::YLeft, Line::Settings::Values::YRight, Line::Settings::VerticalLines, Line::Settings::ZoomOutButton, Pie::Settings, Pie::Settings::Animation, Pie::Settings::Background, Pie::Settings::Balloon, Pie::Settings::ContextMenu, Pie::Settings::ContextMenu::DefaultItems, Pie::Settings::DataLabels, Pie::Settings::ErrorMessages, Pie::Settings::ExportAsImage, Pie::Settings::Group, Pie::Settings::Labels, Pie::Settings::Labels::Label, Pie::Settings::Legend, Pie::Settings::Legend::Key, Pie::Settings::Legend::Values, Pie::Settings::Pie, Pie::Settings::Strings, Stock::Settings, Stock::Settings::Background, Stock::Settings::Balloon, Stock::Settings::Charts, Stock::Settings::Charts::Chart, Stock::Settings::Charts::Chart::Comparing, Stock::Settings::Charts::Chart::Events, Stock::Settings::Charts::Chart::Graphs, Stock::Settings::Charts::Chart::Graphs::Graph, Stock::Settings::Charts::Chart::Graphs::Graph::DataSources, Stock::Settings::Charts::Chart::Graphs::Graph::Legend, Stock::Settings::Charts::Chart::Graphs::Graph::Legend::DigitsAfterDecimal, Stock::Settings::Charts::Chart::Grid, Stock::Settings::Charts::Chart::Grid::X, Stock::Settings::Charts::Chart::Grid::YLeft, Stock::Settings::Charts::Chart::Grid::YRight, Stock::Settings::Charts::Chart::Legend, Stock::Settings::Charts::Chart::Values, Stock::Settings::Charts::Chart::Values::X, Stock::Settings::Charts::Chart::Values::YLeft, Stock::Settings::Charts::Chart::Values::YLeft::DigitsAfterDecimal, Stock::Settings::Charts::Chart::Values::YRight, Stock::Settings::Charts::Chart::Values::YRight::DigitsAfterDecimal, Stock::Settings::ContextMenu, Stock::Settings::ContextMenu::DefaultItems, Stock::Settings::DataReloading, Stock::Settings::DataSetSelector, Stock::Settings::DataSetSelector::DropDown, Stock::Settings::DataSets, Stock::Settings::DataSets::DataSet, Stock::Settings::DataSets::DataSet::Csv, Stock::Settings::DataSets::DataSet::Csv::Columns, Stock::Settings::DateFormats, Stock::Settings::DateFormats::Legend, Stock::Settings::DateFormats::XAxis, Stock::Settings::ErrorMessages, Stock::Settings::ExportAsImage, Stock::Settings::Header, Stock::Settings::NumberFormat, Stock::Settings::NumberFormat::DigitsAfterDecimal, Stock::Settings::NumberFormat::Letters, Stock::Settings::PeriodSelector, Stock::Settings::PeriodSelector::Button, Stock::Settings::PeriodSelector::Input, Stock::Settings::PeriodSelector::Periods, Stock::Settings::PlotArea, Stock::Settings::Scroller, Stock::Settings::Scroller::Grid, Stock::Settings::Scroller::Playback, Stock::Settings::Scroller::Playback::SpeedIndicator, Stock::Settings::Scroller::Values, Stock::Settings::Strings, Stock::Settings::Strings::Months, Stock::Settings::Strings::Weekdays, Xy::Settings, Xy::Settings::Axes, Xy::Settings::Axes::X, Xy::Settings::Axes::Y, Xy::Settings::Background, Xy::Settings::Balloon, Xy::Settings::Bullets, Xy::Settings::ContextMenu, Xy::Settings::ContextMenu::DefaultItems, Xy::Settings::DateFormats, Xy::Settings::DateFormats::AxisValues, Xy::Settings::ErrorMessages, Xy::Settings::ExportAsImage, Xy::Settings::Graphs, Xy::Settings::Graphs::Graph, Xy::Settings::Grid, Xy::Settings::Grid::X, Xy::Settings::Grid::Y, Xy::Settings::Help, Xy::Settings::Help::Balloon, Xy::Settings::Help::Button, Xy::Settings::Labels, Xy::Settings::Labels::Label, Xy::Settings::Legend, Xy::Settings::Legend::Key, Xy::Settings::PlotArea, Xy::Settings::PlotArea::Margins, Xy::Settings::Scroller, Xy::Settings::Strings, Xy::Settings::Strings::Months, Xy::Settings::Values, Xy::Settings::Values::X, Xy::Settings::Values::Y, Xy::Settings::Zoom
Defined in:
lib/ambling/base.rb

Overview

All settings classses include these base functions that populate the data from a hash and generate the xml

Instance Method Summary collapse

Instance Method Details

#build_xml(builder) ⇒ Object

build an xml representation of this subcomponent of the settings using the provided builder



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ambling/base.rb', line 56

def build_xml(builder)
  self.class.send(:const_get, :VALUES).each do |a|
    val = self.send(a)
    if val.respond_to? :build_xml
      builder.tag!(a) {|b| val.build_xml(b) }
    elsif val.is_a? Array
      val.each {|v| builder << v.to_xml }
    elsif not val.nil?
      builder.tag! a, val
    end
  end
end

#initialize(hash = {}) ⇒ Object



16
17
18
# File 'lib/ambling/base.rb', line 16

def initialize(hash = {})
  populate(hash)
end

#populate(hash = {}) ⇒ Object

populate the settings with data from the hash



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ambling/base.rb', line 23

def populate(hash = {})
  hash.each do |k,v|
    val = if v.is_a?(Hash)
      klass = self.class.const_get(k.to_s.camelize)
      klass.new(v)
    elsif v.is_a?(Array)
      klass = self.class.const_get(k.to_s.camelize)
      v.collect {|i| klass.new(i)}
    else
      v
    end
    self.send("#{k}=", val)
  end
end

#to_xml(builder = nil) ⇒ Object

Return an xml representation of these settings



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ambling/base.rb', line 41

def to_xml(builder = nil)
  builder ||= Builder::XmlMarkup.new
  tag = self.class.to_s.split("::").last.downcase
  attr_list = self.class.send(:const_get, :ATTRIBUTES) rescue []
  attrs = attr_list.inject({}) do |h,a|
    val = self.send(a)
    val.nil? ? h : h.merge(a => val)
  end
  builder.tag!(tag, attrs) { self.build_xml(builder) }
  builder.target!
end