Skip to content

Commit

Permalink
refactoring codes by rubocop suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuto committed Sep 23, 2017
1 parent faf598c commit 95b44b8
Show file tree
Hide file tree
Showing 16 changed files with 831 additions and 955 deletions.
194 changes: 96 additions & 98 deletions .rubocop.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ source 'https://rubygems.org'

# Specify your gem's dependencies in review.gemspec
gemspec

16 changes: 8 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ begin
Bundler::GemHelper.install_tasks
rescue LoadError
# ignore if bundler does not exist
warn "Bundler not found"
warn 'Bundler not found'
end

require 'rubygems'
require 'rake/clean'

task :default => [:test, :rubocop]
task default: %i[test rubocop]

desc "Check with rubocop"
desc 'Check with rubocop'
task :rubocop do
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue LoadError
warn "rubocop not found"
warn 'rubocop not found'
end
end

task :test do
ruby("test/run_test.rb")
ruby('test/run_test.rb')
end

begin
Expand All @@ -35,18 +35,18 @@ begin
t.verbose = true
end
rescue LoadError
warn "rcov not found"
warn 'rcov not found'
end

begin
require 'rdoc/task'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
version = File.exist?('VERSION') ? File.read('VERSION') : ''
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "review #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
rescue LoadError
warn "rdoc not found"
warn 'rdoc not found'
end
47 changes: 20 additions & 27 deletions lib/epubmaker/content.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# = content.rb -- Content object for EPUBMaker.
#
# Copyright (c) 2010-2017 Kenshi Muto
Expand All @@ -11,7 +9,6 @@
#

module EPUBMaker

# EPUBMaker::Content represents a content data for EPUBMaker.
# EPUBMaker#contents takes an array of Content.
class Content
Expand All @@ -38,16 +35,16 @@ class Content
# Construct Content object by passing a sequence of parameters or hash.
# Keys of +hash+ relate with each parameters.
# +file+ (or +hash+["file"]) is required. Others are optional.
def initialize(fileorhash, id=nil, media=nil, title=nil, level=nil, notoc=nil, properties=nil, chaptype=nil)
def initialize(fileorhash, id = nil, media = nil, title = nil, level = nil, notoc = nil, properties = nil, chaptype = nil)
if fileorhash.instance_of?(Hash)
@id = fileorhash["id"]
@file = fileorhash["file"]
@media = fileorhash["media"]
@title = fileorhash["title"]
@level = fileorhash["level"]
@notoc = fileorhash["notoc"]
@properties = fileorhash["properties"] || []
@chaptype = fileorhash["chaptype"]
@id = fileorhash['id']
@file = fileorhash['file']
@media = fileorhash['media']
@title = fileorhash['title']
@level = fileorhash['level']
@notoc = fileorhash['notoc']
@properties = fileorhash['properties'] || []
@chaptype = fileorhash['chaptype']
else
@file = fileorhash
@id = id
Expand All @@ -62,9 +59,7 @@ def initialize(fileorhash, id=nil, media=nil, title=nil, level=nil, notoc=nil, p
end

def ==(other)
if self.class != other.class
return false
end
return false unless self.class == other.class
[self.id, self.file, self.media, self.title, self.level, self.notoc, self.chaptype, self.properties] ==
[other.id, other.file, other.media, other.title, other.level, other.notoc, other.chaptype, other.properties]
end
Expand All @@ -73,22 +68,20 @@ def ==(other)

# Complement other parameters by using file parameter.
def complement
@id = @file.gsub(/[\\\/\. ]/, '-') if @id.nil?
@id = @file.gsub(%r{[\\/\. ]}, '-') if @id.nil?
@id = "rv-#{@id}" if @id =~ /\A[^a-z]/i
@media = @file.sub(/.+\./, '').downcase if !@file.nil? && @media.nil?

@media = "application/xhtml+xml" if @media == "xhtml" || @media == "xml" || @media == "html"
@media = "text/css" if @media == "css"
@media = "image/jpeg" if @media == "jpg" || @media == "jpeg" || @media == "image/jpg"
@media = "image/png" if @media == "png"
@media = "image/gif" if @media == "gif"
@media = "image/svg+xml" if @media == "svg" || @media == "image/svg"
@media = "application/vnd.ms-opentype" if @media == "ttf" || @media == "otf"
@media = "application/font-woff" if @media == "woff"
@media = 'application/xhtml+xml' if @media == 'xhtml' || @media == 'xml' || @media == 'html'
@media = 'text/css' if @media == 'css'
@media = 'image/jpeg' if @media == 'jpg' || @media == 'jpeg' || @media == 'image/jpg'
@media = 'image/png' if @media == 'png'
@media = 'image/gif' if @media == 'gif'
@media = 'image/svg+xml' if @media == 'svg' || @media == 'image/svg'
@media = 'application/vnd.ms-opentype' if @media == 'ttf' || @media == 'otf'
@media = 'application/font-woff' if @media == 'woff'

if @id.nil? || @file.nil? || @media.nil?
raise "Type error: #{id}, #{file}, #{media}, #{title}, #{notoc}"
end
raise "Type error: #{id}, #{file}, #{media}, #{title}, #{notoc}" if @id.nil? || @file.nil? || @media.nil?
end
end
end
Loading

0 comments on commit 95b44b8

Please sign in to comment.