class BOAST::Slice::SliceItem
Attributes
first[R]
last[R]
length[R]
step[R]
Public Class Methods
new(slice)
click to toggle source
# File lib/BOAST/Language/Slice.rb, line 21 def initialize(slice) @first = nil @last = nil @step = nil if slice.kind_of?(SliceItem) then copy_slice!(slice) elsif slice.kind_of?(Range) then @first = slice.first @last = slice.last @last = Expression::new(Subtraction, @last, 1) if slice.exclude_end? @length = Expression::new(Subtraction, @last, @first) @length = @length + 1 elsif slice.kind_of?(Array) then @first = slice [0] if slice.length > 0 @last = slice [1] if slice.length > 1 @step = slice [2] if slice.length > 2 @length = Expression::new(Subtraction, @last, @first) @length = @length / @step if @step @length = @length + 1 elsif slice.kind_of?(Symbol) then raise "Invalid Slice item: #{slice.inspect}!" if slice != :all else @first = slice end end
Public Instance Methods
all?()
click to toggle source
# File lib/BOAST/Language/Slice.rb, line 13 def all? @first.nil? end
copy_slice!(slice)
click to toggle source
# File lib/BOAST/Language/Slice.rb, line 47 def copy_slice!(slice) @first = slice.first @last = slice.last @step = slice.step @length = slice.length self end
recurse!(s, d)
click to toggle source
# File lib/BOAST/Language/Slice.rb, line 55 def recurse!(s, d) if all? then copy_slice!(s) else @first = Expression::new(Subtraction, @first, get_array_start) @first = @first * s.step if s.step if s.all? then @first = Expression::new(Addition, d.start, @first ) else @first = Expression::new(Addition, s.first, @first ) end unless scalar? then if s.step then if @step then @step = Expression::new(Multiplication, @step, s.step) else @step = s.step end end @last = @first + (@length-1)*@step end end return self end
scalar?()
click to toggle source
# File lib/BOAST/Language/Slice.rb, line 17 def scalar? not all? and @last.nil? end
to_a()
click to toggle source
# File lib/BOAST/Language/Slice.rb, line 80 def to_a a = [] a.push @first if @first a.push @last if @last a.push @step if @step return a end