acts_as_itemized 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/acts_as_itemized.rb +31 -1
  2. metadata +1 -1
@@ -72,9 +72,39 @@ module ActsAsItemized
72
72
  super
73
73
  end
74
74
 
75
+ def each_itemized(*args, &block)
76
+ # item_type
77
+ type_many = args.first
78
+ type_one = type_many.to_s.singularize
79
+ # options
80
+ options = args.extract_options!
81
+ options.assert_valid_keys(:columns)
82
+ # itemized_options
83
+ itemized_option = self.itemized_options[type_many]
84
+ count = itemized_option[:count]
85
+ columns = options[:columns] || itemized_option[:columns]
86
+ # iterate
87
+ result = []
88
+ columns.each do |column|
89
+ count.times do |i|
90
+ pos = i + 1
91
+ # build key
92
+ key = type_one
93
+ key = "#{key}_#{column}_#{pos}" unless count == 1 && columns.count == 1
94
+ # pass key
95
+ if block_given?
96
+ result << yield(key)
97
+ else
98
+ result << self.send(key)
99
+ end
100
+ end
101
+ end
102
+ result
103
+ end
104
+
75
105
 
76
106
  protected
77
-
107
+
78
108
  # ITEM CHANGES
79
109
  def itemize(*args)
80
110
  args.each do |arg|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_itemized
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Blake Hilscher