class YearArray::Yarray
Attributes
arr[R]
start_time[R]
Public Class Methods
max(ya1, ya2)
click to toggle source
# File lib/year_array/yarray.rb, line 78 def self.max(ya1, ya2) ya1.raise_error_on_misalignment ya2 a = Arr.new(ya1.size){ |i| ya1.arr[i]>ya2.arr[i] ? ya1.arr[i] : ya2.arr[i] } Yarray.new(ya1.year, arr: a) end
min(ya1, ya2)
click to toggle source
# File lib/year_array/yarray.rb, line 71 def self.min(ya1, ya2) ya1.raise_error_on_misalignment ya2 a = Arr.new(ya1.size){ |i| ya1.arr[i]<ya2.arr[i] ? ya1.arr[i] : ya2.arr[i] } Yarray.new(ya1.year, arr: a) end
new(year, value: 0.0, arr: [])
click to toggle source
# File lib/year_array/yarray.rb, line 6 def initialize(year, value: 0.0, arr: []) @start_time = Time.new(year,1,1) nohiy = Yarray.hours_in_year(year) arr = [] if arr.nil? arr = arr.first(nohiy) @arr = arr + Arr.new(nohiy-arr.size, value) end
Public Instance Methods
*(other)
click to toggle source
# File lib/year_array/yarray.rb, line 59 def *(other) raise_error_on_misalignment other a = Arr.new(size){ |i| arr[i]*other.arr[i] } Yarray.new(year, arr: a) end
+(other)
click to toggle source
# File lib/year_array/yarray.rb, line 47 def +(other) raise_error_on_misalignment other a = Arr.new(size){ |i| arr[i]+other.arr[i] } Yarray.new(year, arr: a) end
-(other)
click to toggle source
# File lib/year_array/yarray.rb, line 53 def -(other) raise_error_on_misalignment other a = Arr.new(size){ |i| arr[i]-other.arr[i] } Yarray.new(year, arr: a) end
/(other)
click to toggle source
# File lib/year_array/yarray.rb, line 65 def /(other) raise_error_on_misalignment other a = Arr.new(size){ |i| arr[i]/other.arr[i] } Yarray.new(year, arr: a) end
add(other)
click to toggle source
# File lib/year_array/yarray.rb, line 22 def add(other) raise_error_on_misalignment other @arr.each_with_index{|v, i| @arr[i]=v+other.arr[i]} self end
any?() { |v| ... }
click to toggle source
# File lib/year_array/yarray.rb, line 84 def any?(&block) @arr.any?{|v| yield(v)} end
any_negative?()
click to toggle source
# File lib/year_array/yarray.rb, line 92 def any_negative? any?{|e| e<0.0} end
any_positive?()
click to toggle source
# File lib/year_array/yarray.rb, line 88 def any_positive? any?{|e| e>0.0} end
divide(other)
click to toggle source
# File lib/year_array/yarray.rb, line 40 def divide(other) raise_error_on_misalignment other @arr.each_with_index{|v, i| @arr[i]=v/other.arr[i]} self end
multiply(other)
click to toggle source
# File lib/year_array/yarray.rb, line 34 def multiply(other) raise_error_on_misalignment other @arr.each_with_index{|v, i| @arr[i]=v*other.arr[i]} self end
raise_error_on_misalignment(other)
click to toggle source
# File lib/year_array/yarray.rb, line 96 def raise_error_on_misalignment(other) raise MisalignmentError if !same_year?(other) end
size()
click to toggle source
# File lib/year_array/yarray.rb, line 14 def size @arr.size end
subtract(other)
click to toggle source
# File lib/year_array/yarray.rb, line 28 def subtract(other) raise_error_on_misalignment other @arr.each_with_index{|v, i| @arr[i]=v-other.arr[i]} self end
to_s()
click to toggle source
# File lib/year_array/yarray.rb, line 100 def to_s "start_time: #{start_time}, arr: [#{arr[0..6].join(', ')}, ..., #{arr.last}]" end
year()
click to toggle source
# File lib/year_array/yarray.rb, line 18 def year @start_time.year end