class Contentful::Exporter::Drupal::Tag

Attributes

config[R]
exporter[R]

Public Class Methods

new(exporter, config) click to toggle source
# File lib/drupal/tag.rb, line 8
def initialize(exporter, config)
  @exporter, @config = exporter, config
end

Public Instance Methods

save_tags_as_json() click to toggle source
# File lib/drupal/tag.rb, line 12
def save_tags_as_json
  exporter.create_directory("#{config.entries_dir}/tag")
  config.db[:taxonomy_term_data].each do |tag_row|
    extract_data(tag_row)
  end
end

Private Instance Methods

extract_data(tag_row) click to toggle source
# File lib/drupal/tag.rb, line 21
def extract_data(tag_row)
  puts "Saving tag - id: #{tag_row[:tid]}"
  db_object = map_fields(tag_row)
  exporter.write_json_to_file("#{config.entries_dir}/tag/#{db_object[:id]}.json", db_object)
end
id(tag_id) click to toggle source
# File lib/drupal/tag.rb, line 35
def id(tag_id)
  'tag_' + tag_id.to_s
end
map_fields(row, result = {}) click to toggle source
# File lib/drupal/tag.rb, line 27
def map_fields(row, result = {})
  result[:id] = id(row[:tid])
  result[:name] = row[:name]
  result[:description] = row[:description]
  result[:vocabulary] = vocabulary(row[:vid])
  result
end
tag_vocabulary(tag_vocabulary_id) click to toggle source
# File lib/drupal/tag.rb, line 44
def tag_vocabulary(tag_vocabulary_id)
  config.db[:taxonomy_vocabulary].where(vid: tag_vocabulary_id).first
end
vocabulary(tag_vocabulary_id) click to toggle source
# File lib/drupal/tag.rb, line 39
def vocabulary(tag_vocabulary_id)
  vocabulary = tag_vocabulary(tag_vocabulary_id)
  {type: 'EntryVocabulary', id: "vocabulary_#{vocabulary[:vid]}"}
end