lib/daru/vector.rb in daru-0.2.1 vs lib/daru/vector.rb in daru-0.2.2
- old
+ new
@@ -149,12 +149,10 @@
# Store a hash of labels for values. Supplementary only. Recommend using index
# for proper usage.
attr_accessor :labels
# Store vector data in an array
attr_reader :data
- # Ploting library being used for this vector
- attr_reader :plotting_library
# TODO: Make private.
attr_reader :nil_positions, :nan_positions
# Create a Vector object.
#
@@ -195,25 +193,39 @@
# Initialize non-category type vector
initialize_vector source, opts
end
end
+ # attr_reader for :plotting_library
+ def plotting_library
+ init_plotting_library
+
+ @plotting_library
+ end
+
def plotting_library= lib
case lib
when :gruff, :nyaplot
@plotting_library = lib
if Daru.send("has_#{lib}?".to_sym)
extend Module.const_get(
"Daru::Plotting::Vector::#{lib.to_s.capitalize}Library"
)
end
else
- raise ArguementError, "Plotting library #{lib} not supported. "\
+ raise ArgumentError, "Plotting library #{lib} not supported. "\
'Supported libraries are :nyaplot and :gruff'
end
end
+ # this method is overwritten: see Daru::Vector#plotting_library=
+ def plot(*args, **options, &b)
+ init_plotting_library
+
+ plot(*args, **options, &b)
+ end
+
# Get one or more elements with specified index or a range.
#
# == Usage
# # For vectors employing single layer Index
#
@@ -1479,10 +1491,15 @@
to_df.group_by(*args)
end
private
+ # Will lazily load the plotting library being used for this vector
+ def init_plotting_library
+ self.plotting_library = Daru.plotting_library
+ end
+
def copy(values)
# Make sure values is right-justified to the size of the vector
values.concat([nil] * (size-values.size)) if values.size < size
Daru::Vector.new(values[0...size], index: @index, name: @name)
end
@@ -1512,12 +1529,10 @@
@index = Index.coerce(index || @data.size)
guard_sizes!
@possibly_changed_type = true
- # Include plotting functionality
- self.plotting_library = Daru.plotting_library
end
def parse_source source, opts
if source.is_a?(Hash)
[source.keys, source.values]
@@ -1596,10 +1611,9 @@
end
end
# Raises IndexError when one of the positions is an invalid position
def validate_positions *positions
- positions = [positions] if positions.is_a? Integer
positions.each do |pos|
raise IndexError, "#{pos} is not a valid position." if pos >= size
end
end