Module: Summon::Refworks::Builder

Defined in:
lib/summon/refworks.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(document, options) ⇒ Object



23
24
25
26
# File 'lib/summon/refworks.rb', line 23

def self.build(document, options)
  document.extend self
  document.to_refworks_tagged_format options
end

Instance Method Details

#content_type_to_reference_typeObject



41
42
43
44
# File 'lib/summon/refworks.rb', line 41

def content_type_to_reference_type
  mapping = YAML.load(File.read File.expand_path("../RT.yaml", __FILE__))
  mapping[content_type] || 'Generic'
end

#refworks_normal(value) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/summon/refworks.rb', line 33

def refworks_normal(value)
  if value.kind_of?(Array)
    value.tag_per_value? ? value : [value.join(', ')]
  else
    [value]
  end.compact
end

#refworks_tagsObject



28
29
30
31
# File 'lib/summon/refworks.rb', line 28

def refworks_tags
  filename = File.expand_path("../mappings.rb", __FILE__)
  eval(File.read(filename), binding, filename, 1)
end

#to_refworks_tagged_format(options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/summon/refworks.rb', line 46

def to_refworks_tagged_format(options)
  {}.tap do |tags|
    refworks_tags.merge(options).each do |tag, mapping|
      tags[tag] = refworks_normal case mapping
      when Symbol then send(mapping)
      when Proc then mapping.call()
      else mapping; end
    end
  end
end