Class: Highcharts::Base
- Inherits:
-
Object
- Object
- Highcharts::Base
- Defined in:
- lib/highcharts/base.rb
Direct Known Subclasses
Axis::Events, Axis::PlotBands, Axis::PlotLines, Axis::StackLabels, Axis::X, Axis::Y, Chart, Colors, Credits, Labels, Legend, PlotOptions, PlotOptions::PlotType, PlotOptions::PlotType::Events, PlotOptions::PlotType::Marker, PlotOptions::PlotType::Marker::States, PlotOptions::PlotType::States, PlotOptions::PlotType::States::Hover, Point, Point::Events, Series, Title, Tooltip
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#skip_quotation ⇒ Object
readonly
Returns the value of attribute skip_quotation.
-
#suboptions ⇒ Object
readonly
Returns the value of attribute suboptions.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
-
#to_json ⇒ Object
This method is used in the parent class, Highcharts, in order to render the options in a JavaScript-friendly (JSON) format.
Constructor Details
#initialize(opts = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/highcharts/base.rb', line 6 def initialize(opts = {}) @options = opts @suboptions ||= {} # We want to make sure that options in the end is actually a Hash of options, or an Array of hashes of options. # When default is defined in a subclass and the passed options are not a Hash or Array, we want to replace options # with a Hash where the only key/value pair is the default key and the options value. if !.is_a?(Hash) || (.is_a?(Array) && !.first.is_a?(Hash)) if default.present? @options = {default => } else raise ArgumentError, "You must pass a Hash to #{self.class}. You passed #{.inspect}" end end # If there is an option that is available as a suboption to the current class, # let's set the option to an instance of that subclass. .each do |k, v| @options[k] = "Highcharts::#{[k]}".constantize.new(v) if .keys.include?(k) end end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'lib/highcharts/base.rb', line 4 def default @default end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/highcharts/base.rb', line 4 def @options end |
#skip_quotation ⇒ Object (readonly)
Returns the value of attribute skip_quotation.
4 5 6 |
# File 'lib/highcharts/base.rb', line 4 def skip_quotation @skip_quotation end |
#suboptions ⇒ Object (readonly)
Returns the value of attribute suboptions.
4 5 6 |
# File 'lib/highcharts/base.rb', line 4 def @suboptions end |
Instance Method Details
#inspect ⇒ Object
28 29 30 |
# File 'lib/highcharts/base.rb', line 28 def inspect "#<#{self.class}:0x#{object_id} #{.inspect}>" end |
#to_json ⇒ Object
This method is used in the parent class, Highcharts, in order to render the options in a JavaScript-friendly (JSON) format.
33 34 35 36 37 38 39 40 41 |
# File 'lib/highcharts/base.rb', line 33 def to_json json = .collect do |k, v| "\"#{k}\":" + (.keys.include?(k) && !v.is_a?(Array) ? '{' : '') + (v.is_a?(Array) && .keys.include?(k) ? "[{#{v.collect(&:to_json).join('},{')}}]" : check_quotation(k, v.to_json)) + (.keys.include?(k) && !v.is_a?(Array) ? '}' : '') end json.join(',') end |