lfa-wordpress-import/lib/wordpress/author.rb

47 lines
969 B
Ruby
Raw Normal View History

2014-03-04 22:47:53 +00:00
module WordPressImport
class Author
attr_reader :author_node
2014-03-04 22:47:53 +00:00
def initialize(author_node)
@author_node = author_node
end
2014-03-06 04:27:57 +00:00
def name
name = author_node.xpath("wp:author_display_name").text
name = author_node.xpath("wp:author_first_name").text + " " + author_node.xpath("wp:author_first_name").text if name.blank?
name
end
2014-03-04 22:47:53 +00:00
def login
author_node.xpath("wp:author_login").text
end
2014-03-04 22:47:53 +00:00
def email
author_node.xpath("wp:author_email").text
end
2014-03-04 22:47:53 +00:00
def ==(other)
login == other.login
end
2014-03-04 22:47:53 +00:00
def inspect
"WordPress::Author: #{login} <#{email}>"
end
2014-03-06 04:27:57 +00:00
def to_rails
user = ::User.find_or_initialize_by_email(email)
user.wp_username = login
2014-03-04 22:47:53 +00:00
unless user.persisted?
2014-03-06 04:27:57 +00:00
user.name = name
2014-03-04 22:47:53 +00:00
user.password = 'password'
user.password_confirmation = 'password'
end
2014-03-06 04:27:57 +00:00
user.save
puts "User #{login} imported."
2014-03-04 22:47:53 +00:00
user
end
end
2014-03-04 22:47:53 +00:00
end