lib/fb2rb.rb in fb2rb-0.3.0 vs lib/fb2rb.rb in fb2rb-0.4.0
- old
+ new
@@ -114,10 +114,20 @@
add_binary_io name, io, content_type
end
end
end
+ def add_stylesheet(content_type, filename_or_io)
+ if filename_or_io.respond_to?(:read)
+ add_stylesheet_io(content_type, filename_or_io)
+ else
+ File.open(filename_or_io, 'r') do |io|
+ add_stylesheet_io(content_type, io)
+ end
+ end
+ end
+
# Writes compressed FB2 to file or IO object. If file exists, it will be overwritten.
def write_compressed(filename_or_io = StringIO.new)
if filename_or_io.respond_to?(:write)
Zip::OutputStream.write_buffer(filename_or_io) do |zos|
write_to_zip(zos)
@@ -163,10 +173,17 @@
io.binmode
content = io.read
@binaries << Binary.new(name, content, content_type)
self
end
+
+ def add_stylesheet_io(content_type, io)
+ io.binmode
+ content = io.read
+ @stylesheets << Stylesheet.new(content_type, content)
+ self
+ end
end
# Holds <description> data
class Description
# @return [FB2rb::TitleInfo]
@@ -365,11 +382,11 @@
@history = history
@publishers = publishers
end
# @return [FB2rb::DocumentInfo]
- def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
+ def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
date = xml.at("./#{fb2_prefix}:date")
DocumentInfo.new(
xml.xpath("./#{fb2_prefix}:author").map do |node|
Author.parse(node, fb2_prefix)
end,
@@ -457,11 +474,11 @@
@translators = translators
@sequences = sequences
end
# @return [FB2rb::TitleInfo]
- def self.parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
+ def self.parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
date = xml.at("./#{fb2_prefix}:date")
coverpage = xml.at("./#{fb2_prefix}:coverpage")
TitleInfo.new(
xml.xpath("./#{fb2_prefix}:genre/text()").map(&:text),
xml.xpath("./#{fb2_prefix}:author").map do |node|
@@ -481,11 +498,11 @@
Sequence.parse(node)
end
)
end
- def to_xml(xml, tag) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
+ def to_xml(xml, tag) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
xml.send(tag) do
genres.each do |genre|
xml.genre(genre)
end
authors.each do |author|
@@ -631,10 +648,10 @@
xml.xpath("./#{fb2_prefix}:email/text()").map(&:text),
xml.at("./#{fb2_prefix}:id/text()")&.text
)
end
- def to_xml(xml, tag) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
+ 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?