Module: CFF::Util
- Included in:
- ModelPart
- Defined in:
- lib/cff/util.rb
Overview
Util provides utility methods useful throughout the rest of the CFF library.
Util does not provide any methods or fields for the public API.
Instance Method Summary collapse
- #build_actor_collection!(source) ⇒ Object
- #fields_to_hash(fields) ⇒ Object
-
#method_to_field(name) ⇒ Object
:stopdoc:.
- #normalize_modelpart_array!(array) ⇒ Object
Instance Method Details
#build_actor_collection!(source) ⇒ Object
28 29 30 31 32 |
# File 'lib/cff/util.rb', line 28 def build_actor_collection!(source) source.map! do |s| s.has_key?('given-names') ? Person.new(s) : Entity.new(s) end end |
#fields_to_hash(fields) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cff/util.rb', line 38 def fields_to_hash(fields) hash = {} fields.each do |field, value| if value.respond_to?(:map) unless value.empty? hash[field] = value.map do |v| v.respond_to?(:fields) ? v.fields : v.to_s end end else hash[field] = value.respond_to?(:fields) ? value.fields : value end end hash end |
#method_to_field(name) ⇒ Object
:stopdoc:
24 25 26 |
# File 'lib/cff/util.rb', line 24 def method_to_field(name) name.tr('_', '-') end |
#normalize_modelpart_array!(array) ⇒ Object
34 35 36 |
# File 'lib/cff/util.rb', line 34 def normalize_modelpart_array!(array) array.select! { |i| i.respond_to?(:fields) } end |