Class: Yahm::Mapping
- Inherits:
-
Object
- Object
- Yahm::Mapping
- Defined in:
- lib/yahm/mapping.rb
Instance Attribute Summary collapse
-
#thread_pool_size ⇒ Object
Returns the value of attribute thread_pool_size.
-
#use_threads ⇒ Object
Returns the value of attribute use_threads.
Instance Method Summary collapse
- #apply_to(input_hash, options = {}) ⇒ Object
-
#initialize(options = {}, &block) ⇒ Mapping
constructor
A new instance of Mapping.
Constructor Details
#initialize(options = {}, &block) ⇒ Mapping
Returns a new instance of Mapping.
8 9 10 11 12 13 14 15 16 |
# File 'lib/yahm/mapping.rb', line 8 def initialize( = {}, &block) @context = [:context] @rules = [] @result = nil @use_threads = [:use_threads] || false @thread_pool_size = [:thread_pool_size] || 2 self.instance_eval(&block) if block end |
Instance Attribute Details
#thread_pool_size ⇒ Object
Returns the value of attribute thread_pool_size.
5 6 7 |
# File 'lib/yahm/mapping.rb', line 5 def thread_pool_size @thread_pool_size end |
#use_threads ⇒ Object
Returns the value of attribute use_threads.
6 7 8 |
# File 'lib/yahm/mapping.rb', line 6 def use_threads @use_threads end |
Instance Method Details
#apply_to(input_hash, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yahm/mapping.rb', line 18 def apply_to(input_hash, = {}) @result = {} if @use_threads thread_pool = Thread.pool(@thread_pool_size) if @use_threads @rules.each do |rule| thread_pool.process do apply_rule(rule, input_hash, @result, ) end end thread_pool.shutdown else @rules.each do |rule| apply_rule(rule, input_hash, @result, ) end end @result end |