Class: Ziya::Charts::Support::Base
- Inherits:
-
Object
- Object
- Ziya::Charts::Support::Base
- Defined in:
- lib/ziya/charts/support/base.rb
Overview
:nodoc:
Direct Known Subclasses
AxisCategory, AxisTicks, AxisValue, Bevel, Blur, Button, ChartBorder, ChartGridH, ChartGridV, ChartGuide, ChartLabel, ChartNote, ChartPref, ChartRect, ChartTransition, Circle, ContextMenu, Draw, DrawBase, Filter, FlashToJavascript, Glow, Image, Legend, Line, Link, LinkData, Rect, Scroll, Series, SeriesColor, SeriesExplode, Shadow, Text, Tooltip, Update, Gauges::Support::Base, Maps::Support::Base
Class Method Summary collapse
-
.attributes ⇒ Object
———————————————————————– Class accessor.
-
.has_attribute(*args) ⇒ Object
———————————————————————– defines attribute accessors for a given component.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#attributes_for(an_instance) ⇒ Object
————————————————————————- fetch attributes for a give component.
-
#configured? ⇒ Boolean
————————————————————————- checks if a give component properties have been set.
-
#flatten(xml) ⇒ Object
————————————————————————- Flattens out this component to xml.
-
#has_sub_components ⇒ Object
————————————————————————- Checks if one of the options is an array.
-
#initialize(opts = {}) ⇒ Base
constructor
————————————————————————- initializes component from hash.
-
#merge(parent_attributes, force = false) ⇒ Object
————————————————————————- merge attributes with overriden component.
-
#options ⇒ Object
————————————————————————- calls all attribute methods and gather the various props into a hash.
-
#options_as_string ⇒ Object
————————————————————————- Turns options hash into string representation.
Constructor Details
#initialize(opts = {}) ⇒ Base
initializes component from hash
41 42 43 44 45 |
# File 'lib/ziya/charts/support/base.rb', line 41 def initialize( opts={} ) opts.each_pair do |k,v| self.send( "#{k}=", v ) end end |
Class Method Details
.attributes ⇒ Object
Class accessor. Retrieve class level preferences
34 35 36 |
# File 'lib/ziya/charts/support/base.rb', line 34 def attributes # :nodoc: @attributes ||= {} end |
.has_attribute(*args) ⇒ Object
defines attribute accessors for a given component
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ziya/charts/support/base.rb', line 19 def has_attribute(*args) # :nodoc: class_name = self.to_s args.each do |attribute| # add the attribute to the collection making sure to create a new array if one doesn't exist attributes[class_name] = [] if attributes[class_name].nil? attributes[class_name] << attribute # create the accessor methods for the attribute unless self.instance_methods.include?(attribute.to_s) && self.instance_methods.include?("#{attribute.to_s}=") self.module_eval "attr_accessor :#{attribute}" end end end |
Instance Method Details
#==(other) ⇒ Object
47 48 49 50 51 |
# File 'lib/ziya/charts/support/base.rb', line 47 def ==( other ) self..each_pair do |k,v| return false unless other.send( k ) == v end end |
#attributes_for(an_instance) ⇒ Object
fetch attributes for a give component
120 121 122 123 124 |
# File 'lib/ziya/charts/support/base.rb', line 120 def attributes_for( an_instance ) attrs = self.class.attributes[an_instance.class.name] raise "Unable to get attributes for #{an_instance}" unless attrs attrs end |
#configured? ⇒ Boolean
checks if a give component properties have been set. return true if one or more props have been set. False otherwise…
82 83 84 |
# File 'lib/ziya/charts/support/base.rb', line 82 def configured? !.empty? end |
#flatten(xml) ⇒ Object
Flattens out this component to xml
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ziya/charts/support/base.rb', line 65 def flatten( xml ) hash = has_sub_components pref = self.class.name.ziya_demodulize.ziya_underscore if hash and ! hash.empty? self.class.module_eval <<-XML xml.#{pref}( #{} ) do hash.each{ |k,v| v.flatten( xml ) } end XML else self.class.module_eval "xml.#{pref}( #{} )" end end |
#has_sub_components ⇒ Object
Checks if one of the options is an array
88 89 90 91 92 93 |
# File 'lib/ziya/charts/support/base.rb', line 88 def has_sub_components .each_pair do |k, v| return v if v.is_a? YAML::Omap end nil end |
#merge(parent_attributes, force = false) ⇒ Object
merge attributes with overriden component
55 56 57 58 59 60 61 |
# File 'lib/ziya/charts/support/base.rb', line 55 def merge( parent_attributes, force=false ) attributes_for(self).each do |attr| unless parent_attributes.send(attr).nil? send("#{attr}=", parent_attributes.send(attr)) end end end |
#options ⇒ Object
calls all attribute methods and gather the various props into a hash
97 98 99 100 101 102 103 104 |
# File 'lib/ziya/charts/support/base.rb', line 97 def = {} attributes_for(self).each do |p| option = self.send(p.to_sym) [p] = option if option end end |
#options_as_string ⇒ Object
Turns options hash into string representation
108 109 110 111 112 113 114 115 116 |
# File 'lib/ziya/charts/support/base.rb', line 108 def buff = [] opts = opts.keys.sort{ |a,b| a.to_s <=> b.to_s }.each do |k| value = opts[k] buff << sprintf( ":%s => '%s'", k, value.to_s ) if value and !value.is_a? YAML::Omap end buff.join( "," ) end |