Module: Scruffy::Helpers::PointContainer

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

Overview

Scruffy::Helpers::PointContainer

Author

Mat Schaffer

Date

March 22nd, 2007

Allows all standard point operations to be called on both Array and Hash

Defined Under Namespace

Modules: Array, Hash

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(point_set) ⇒ Object



10
11
12
# File 'lib/scruffy/helpers/point_container.rb', line 10

def self.extended point_set
  point_set.extend(const_get(point_set.class.to_s))
end

Instance Method Details

#inject_with_index(memo) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/scruffy/helpers/point_container.rb', line 34

def inject_with_index memo
  index = 0
  inject(memo) do |memo, item|
    ret = yield memo, item, index
    index = index.succ
    ret
  end
end

#maximum_valueObject



22
23
24
# File 'lib/scruffy/helpers/point_container.rb', line 22

def maximum_value
  sortable_values.sort.last
end

#minimum_valueObject



26
27
28
# File 'lib/scruffy/helpers/point_container.rb', line 26

def minimum_value
  sortable_values.sort.first
end

#sortable_valuesObject



14
15
16
# File 'lib/scruffy/helpers/point_container.rb', line 14

def sortable_values
  values.find_all { |v| v.respond_to? :<=> }
end

#sumObject



30
31
32
# File 'lib/scruffy/helpers/point_container.rb', line 30

def sum
  summable_values.inject(0) { |sum, i| sum += i }
end

#summable_valuesObject



18
19
20
# File 'lib/scruffy/helpers/point_container.rb', line 18

def summable_values
  values.find_all { |v| v.respond_to? :+ }
end