class Workarea::Blog::Import::Wordpress::Attachment

Public Class Methods

new(url) click to toggle source
# File lib/workarea/blog/import/wordpress/attachment.rb, line 6
def initialize(url)
  @attachment_path = url
end

Public Instance Methods

save() click to toggle source
# File lib/workarea/blog/import/wordpress/attachment.rb, line 10
def save
  attributes = {
    name: file_name,
    tag_list: 'Wordpress',
    file: image_file
  }

  asset = Workarea::Content::Asset.create!(attributes)
  puts "Created Asset: #{asset.name}"
  asset
end

Private Instance Methods

file_name() click to toggle source
# File lib/workarea/blog/import/wordpress/attachment.rb, line 32
def file_name
  path = uri.path
  path.rpartition('.').first.split('/').join('-')
end
image_file() click to toggle source
# File lib/workarea/blog/import/wordpress/attachment.rb, line 24
def image_file
  Net::HTTP.get(uri)
end
uri() click to toggle source
# File lib/workarea/blog/import/wordpress/attachment.rb, line 28
def uri
  URI.parse(@attachment_path)
end