2014-03-04 22:47:53 +00:00
|
|
|
module WordPressImport
|
|
|
|
class Author
|
|
|
|
attr_reader :author_node
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2014-03-04 22:47:53 +00:00
|
|
|
def initialize(author_node)
|
|
|
|
@author_node = author_node
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
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
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2014-03-04 22:47:53 +00:00
|
|
|
def email
|
|
|
|
author_node.xpath("wp:author_email").text
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2014-03-04 22:47:53 +00:00
|
|
|
def ==(other)
|
|
|
|
login == other.login
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2014-03-04 22:47:53 +00:00
|
|
|
def inspect
|
|
|
|
"WordPress::Author: #{login} <#{email}>"
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
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'
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
2014-03-06 04:27:57 +00:00
|
|
|
user.save
|
2014-03-04 22:47:53 +00:00
|
|
|
user
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
end
|
2014-03-04 22:47:53 +00:00
|
|
|
end
|