Sha256: 28fca4e850996fa0d6d779fe8f974f7990bd3188b560ea76ed26ad32477379d1

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

require_relative 'blog'

module Contentful
  module Exporter
    module Wordpress
      class Tag < Blog
        attr_reader :xml, :settings

        def initialize(xml, settings)
          @xml = xml
          @settings = settings
        end

        def tags_extractor
          output_logger.info 'Extracting blog tags...'
          create_directory("#{settings.entries_dir}/tag")
          extract_tags
        end

        private

        def extract_tags
          tags.each_with_object([]) do |tag, tags|
            normalized_tag = extracted_data(tag)
            write_json_to_file("#{settings.entries_dir}/tag/#{id(tag)}.json", normalized_tag)
            tags << normalized_tag
          end
        end

        def extracted_data(tag)
          {
            id: id(tag),
            nicename: slug(tag),
            name: name(tag)
          }
        end

        def tags
          xml.xpath('//wp:tag').to_a
        end

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

        def slug(tag)
          tag.xpath('wp:tag_slug').text
        end

        def name(tag)
          tag.xpath('wp:tag_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/tag.rb
wordpress-exporter-0.1.0 lib/wordpress/tag.rb
wordpress-exporter-0.0.2 lib/wordpress/tag.rb
wordpress-exporter-0.0.1 lib/wordpress/tag.rb