Class: FB2rb::Author
- Inherits:
-
Object
- Object
- FB2rb::Author
- Defined in:
- lib/fb2rb.rb
Overview
Holds <author> data
Instance Attribute Summary collapse
- #emails ⇒ Array<String>
- #first_name ⇒ String?
- #home_pages ⇒ Array<String>
- #id ⇒ String?
- #last_name ⇒ String?
- #middle_name ⇒ String?
- #nickname ⇒ String?
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(first_name: nil, middle_name: nil, last_name: nil, nickname: nil, home_pages: [], emails: [], id: nil) ⇒ Author
constructor
rubocop:disable Metrics/ParameterLists.
-
#to_xml(xml, tag) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength.
Constructor Details
#initialize(first_name: nil, middle_name: nil, last_name: nil, nickname: nil, home_pages: [], emails: [], id: nil) ⇒ Author
rubocop:disable Metrics/ParameterLists
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 |
# File 'lib/fb2rb.rb', line 625 def initialize(first_name: nil, # rubocop:disable Metrics/ParameterLists middle_name: nil, last_name: nil, nickname: nil, home_pages: [], emails: [], id: nil) @first_name = first_name @middle_name = middle_name @last_name = last_name @nickname = nickname @home_pages = home_pages @emails = emails @id = id end |
Instance Attribute Details
#emails ⇒ Array<String>
621 622 623 |
# File 'lib/fb2rb.rb', line 621 def emails @emails end |
#first_name ⇒ String?
611 612 613 |
# File 'lib/fb2rb.rb', line 611 def first_name @first_name end |
#home_pages ⇒ Array<String>
619 620 621 |
# File 'lib/fb2rb.rb', line 619 def home_pages @home_pages end |
#id ⇒ String?
623 624 625 |
# File 'lib/fb2rb.rb', line 623 def id @id end |
#last_name ⇒ String?
615 616 617 |
# File 'lib/fb2rb.rb', line 615 def last_name @last_name end |
#middle_name ⇒ String?
613 614 615 |
# File 'lib/fb2rb.rb', line 613 def middle_name @middle_name end |
#nickname ⇒ String?
617 618 619 |
# File 'lib/fb2rb.rb', line 617 def nickname @nickname end |
Class Method Details
.parse(xml, fb2_prefix) ⇒ FB2rb::Author
642 643 644 645 646 647 648 649 650 651 652 |
# File 'lib/fb2rb.rb', line 642 def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/CyclomaticComplexity Author.new( first_name: xml.at("./#{fb2_prefix}:first-name/text()")&.text, middle_name: xml.at("./#{fb2_prefix}:middle-name/text()")&.text, last_name: xml.at("./#{fb2_prefix}:last-name/text()")&.text, nickname: xml.at("./#{fb2_prefix}:nickname/text()")&.text, home_pages: xml.xpath("./#{fb2_prefix}:home-page/text()").map(&:text), emails: xml.xpath("./#{fb2_prefix}:email/text()").map(&:text), id: xml.at("./#{fb2_prefix}:id/text()")&.text ) end |
Instance Method Details
#to_xml(xml, tag) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 |
# File 'lib/fb2rb.rb', line 654 def to_xml(xml, tag) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength xml.send(tag) do xml.send('first-name', @first_name) unless @first_name.nil? xml.send('middle-name', @middle_name) unless @middle_name.nil? xml.send('last-name', @last_name) unless @last_name.nil? xml.nickname(@nickname) unless @nickname.nil? @home_pages.each do |home_page| xml.send('home-page', home_page) end @emails.each do |email| xml.email(email) end xml.id(@id) unless @id.nil? end end |