Module: Scruffy::Helpers::PointContainer::Array_ext

Defined in:
lib/scruffy/helpers/point_container.rb

Instance Method Summary collapse

Instance Method Details

#each_point(&block) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/scruffy/helpers/point_container.rb', line 69

def each_point(&block)
  if is_coordinate_list?
    each{|x,y|block.call(x,y)}
  else
    size.times{|k|block.call(k,self[k])}
  end
end

#is_coordinate_list?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'lib/scruffy/helpers/point_container.rb', line 62

def is_coordinate_list?
  if any? && first.is_a?(Array) && first.size == 2
    return true
  end
  return false
end

#keysObject



57
58
59
60
# File 'lib/scruffy/helpers/point_container.rb', line 57

def keys
  return [0,size-1] unless is_coordinate_list?
  collect { |x,y| x}
end

#valuesObject



52
53
54
55
# File 'lib/scruffy/helpers/point_container.rb', line 52

def values
  return self unless is_coordinate_list?
  collect { |x,y| y}
end