Class: Beret::BlockSet
- Inherits:
-
Object
- Object
- Beret::BlockSet
- Defined in:
- lib/beret/block_set.rb
Instance Method Summary collapse
- #blocks ⇒ Object
- #find(field_name, options = {}) ⇒ Object
-
#initialize(block_json) ⇒ BlockSet
constructor
A new instance of BlockSet.
- #to_json ⇒ Object
- #update(field_name, options = {}) ⇒ Object
Constructor Details
#initialize(block_json) ⇒ BlockSet
Returns a new instance of BlockSet.
4 5 6 |
# File 'lib/beret/block_set.rb', line 4 def initialize(block_json) @block_json = block_json end |
Instance Method Details
#blocks ⇒ Object
29 30 31 32 33 |
# File 'lib/beret/block_set.rb', line 29 def blocks @blocks ||= block_json.map do |block| Block.new(block) end end |
#find(field_name, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/beret/block_set.rb', line 8 def find(field_name, ={}) results = Search.new(blocks, field_name, ).results if block_given? results.each do |result| yield result.value, result.block end end results end |
#to_json ⇒ Object
35 36 37 |
# File 'lib/beret/block_set.rb', line 35 def to_json blocks.map(&:to_json) end |
#update(field_name, options = {}) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/beret/block_set.rb', line 20 def update(field_name, ={}) results = find(field_name, ) results.each do |result| new_value = yield result.value, result.block result.block.update_attribute(field_name, new_value) end end |