Sha256: 599d74dc2c3edb6589d6b7ff1d1da2216403df311379fb9720cbcdf1cbcfd3bc

Contents?: true

Size: 1.31 KB

Versions: 4

Compression:

Stored size: 1.31 KB

Contents

require_relative 'blog'

module Contentful
  module Exporter
    module Wordpress
      class Category < Blog
        def initialize(xml, settings)
          @xml = xml
          @settings = settings
        end

        def categories_extractor
          output_logger.info 'Extracting blog categories...'
          create_directory("#{settings.entries_dir}/category")
          extract_categories
        end

        private

        def extract_categories
          categories.each_with_object([]) do |category, categories|
            normalized_category = extracted_category(category)
            write_json_to_file("#{settings.entries_dir}/category/#{id(category)}.json", normalized_category)
            categories << normalized_category
          end
        end

        def extracted_category(category)
          {
            id: id(category),
            nicename: nice_name(category),
            name: name(category)
          }
        end

        def categories
          xml.xpath('//wp:category').to_a
        end

        def id(category)
          "category_#{category.xpath('wp:term_id').text}"
        end

        def nice_name(category)
          category.xpath('wp:category_nicename').text
        end

        def name(category)
          category.xpath('wp:cat_name').text
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
wordpress-exporter-0.2.0 lib/wordpress/category.rb
wordpress-exporter-0.1.0 lib/wordpress/category.rb
wordpress-exporter-0.0.2 lib/wordpress/category.rb
wordpress-exporter-0.0.1 lib/wordpress/category.rb