Class: NdTranscriber::Copier
- Inherits:
-
Object
- Object
- NdTranscriber::Copier
- Defined in:
- lib/nd_transcriber/copier.rb
Instance Attribute Summary collapse
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#origin ⇒ Object
Returns the value of attribute origin.
Instance Method Summary collapse
- #copy(field, to: field) ⇒ Object
- #copy_fields(*fields) ⇒ Object
-
#initialize(origin, dest) ⇒ Copier
constructor
A new instance of Copier.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(origin, dest) ⇒ Copier
Returns a new instance of Copier.
5 6 7 |
# File 'lib/nd_transcriber/copier.rb', line 5 def initialize origin, dest self.origin, self.dest = origin, dest end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
34 35 36 |
# File 'lib/nd_transcriber/copier.rb', line 34 def method_missing method, *args, &block dest.send(method, *args, &block) end |
Instance Attribute Details
#dest ⇒ Object
Returns the value of attribute dest.
3 4 5 |
# File 'lib/nd_transcriber/copier.rb', line 3 def dest @dest end |
#origin ⇒ Object
Returns the value of attribute origin.
3 4 5 |
# File 'lib/nd_transcriber/copier.rb', line 3 def origin @origin end |
Instance Method Details
#copy(field, to: field) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nd_transcriber/copier.rb', line 22 def copy field, to: field value = (field && origin.respond_to?(field) ? origin.send(field) : nil ) value = yield(value) if block_given? if to.is_a?(Array) to.each do |f| dest.send("#{f}=", value) end else dest.send("#{to}=", value) end end |
#copy_fields(*fields) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nd_transcriber/copier.rb', line 9 def copy_fields *fields fields.each do |field| if field.is_a?(Hash) field.each_pair do |from, to| copy from, to: to end else copy field end end dest end |