Class: Contentful::Exporter::Wordpress::Blog

Inherits:
Object
  • Object
show all
Defined in:
lib/wordpress/blog.rb

Direct Known Subclasses

Author, Category, Post, Tag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_document, settings) ⇒ Blog

Returns a new instance of Blog.



10
11
12
13
# File 'lib/wordpress/blog.rb', line 10

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

Instance Attribute Details

#settingsObject (readonly)

Returns the value of attribute settings.



8
9
10
# File 'lib/wordpress/blog.rb', line 8

def settings
  @settings
end

#xmlObject (readonly)

Returns the value of attribute xml.



8
9
10
# File 'lib/wordpress/blog.rb', line 8

def xml
  @xml
end

Instance Method Details

#blog_extractorObject



15
16
17
18
# File 'lib/wordpress/blog.rb', line 15

def blog_extractor
  create_directory(settings.data_dir)
  extract_blog
end

#create_directory(path) ⇒ Object



38
39
40
# File 'lib/wordpress/blog.rb', line 38

def create_directory(path)
  FileUtils.mkdir_p(path) unless File.directory?(path)
end


33
34
35
36
# File 'lib/wordpress/blog.rb', line 33

def link_asset(asset)
  asset.keep_if { |key, _v| key if key == :id }
  asset.merge!(type: 'File')
end

#link_entry(entry_or_entries) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/wordpress/blog.rb', line 20

def link_entry(entry_or_entries)
  link = ->(entry) {
    entry.keep_if { |key, _v| key if key == :id }
    entry.merge!(type: 'Entry')
  }

  if entry_or_entries.is_a? Array
    entry_or_entries.each(&link)
  else
    link.call(entry_or_entries)
  end
end

#output_loggerObject



48
49
50
# File 'lib/wordpress/blog.rb', line 48

def output_logger
  Logger.new(STDOUT)
end

#write_json_to_file(path, data) ⇒ Object



42
43
44
45
46
# File 'lib/wordpress/blog.rb', line 42

def write_json_to_file(path, data)
  File.open(path, 'w') do |file|
    file.write(JSON.pretty_generate(data))
  end
end