Class: FB2rb::Description

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

Overview

Holds <description> data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title_info: TitleInfo.new, document_info: DocumentInfo.new, publish_info: nil, src_title_info: nil, custom_infos: []) ⇒ Description

TODO: <output>



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/fb2rb.rb', line 202

def initialize(title_info: TitleInfo.new,
               document_info: DocumentInfo.new,
               publish_info: nil,
               src_title_info: nil,
               custom_infos: [])
  @title_info = title_info
  @document_info = document_info
  @publish_info = publish_info
  @src_title_info = src_title_info
  @custom_infos = custom_infos
end

Instance Attribute Details

#custom_infosArray<FB2rb::CustomInfo>

Returns:



198
199
200
# File 'lib/fb2rb.rb', line 198

def custom_infos
  @custom_infos
end

#document_infoFB2rb::DocumentInfo

Returns:



194
195
196
# File 'lib/fb2rb.rb', line 194

def document_info
  @document_info
end

#publish_infoFB2rb::PublishInfo?

Returns:



196
197
198
# File 'lib/fb2rb.rb', line 196

def publish_info
  @publish_info
end

#src_title_infoFB2rb::TitleInfo?

Returns:



192
193
194
# File 'lib/fb2rb.rb', line 192

def src_title_info
  @src_title_info
end

#title_infoFB2rb::TitleInfo

Returns:



190
191
192
# File 'lib/fb2rb.rb', line 190

def title_info
  @title_info
end

Class Method Details

.parse(xml, fb2_prefix, xlink_prefix) ⇒ FB2rb::Description

Returns:



215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/fb2rb.rb', line 215

def self.parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/MethodLength
  publish_info_xml = xml.at("./#{fb2_prefix}:publish-info")
  src_title_info_xml = xml.at("./#{fb2_prefix}:src-title-info")
  Description.new(
    title_info: TitleInfo.parse(xml.at("./#{fb2_prefix}:title-info"), fb2_prefix, xlink_prefix),
    document_info: DocumentInfo.parse(xml.at("./#{fb2_prefix}:document-info"), fb2_prefix),
    publish_info: publish_info_xml.nil? ? nil : PublishInfo.parse(publish_info_xml, fb2_prefix),
    src_title_info: src_title_info_xml.nil? ? nil : TitleInfo.parse(src_title_info_xml, fb2_prefix, xlink_prefix),
    custom_infos: xml.xpath("./#{fb2_prefix}:custom-info").map do |node|
      CustomInfo.parse(node)
    end
  )
end

Instance Method Details

#to_xml(xml) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
# File 'lib/fb2rb.rb', line 229

def to_xml(xml)
  xml.description do
    @title_info.to_xml(xml, :'title-info')
    @src_title_info&.to_xml(xml, :'src-title-info')
    @document_info.to_xml(xml)
    @publish_info&.to_xml(xml)
    @custom_infos.each do |custom_info|
      custom_info.to_xml(xml)
    end
  end
end