Skip to content

Instantly share code, notes, and snippets.

@th1agoalmeida
Created January 16, 2023 18:40
Show Gist options
  • Save th1agoalmeida/3242ea1b78f929cc0317c9025f38828c to your computer and use it in GitHub Desktop.
Save th1agoalmeida/3242ea1b78f929cc0317c9025f38828c to your computer and use it in GitHub Desktop.
class BookCommand < AppCommand
def self.call args
log :higher, "Called #{self}.#{__method__} with args #{args}"
new(args).call
end
def initialize args
@args = args
end
def call
log :higher, "Called #{self}.#{__method__}"
fname = "ruby.pdf"
# path = "#{source_location_radical}/#{fname}"
path = fname
does_exist = File.exist? path
log "#{path} does_exist? #{does_exist}"
log "filtering"
@count = 0
# cover
add_pages 0..1
# title and authors
add_pages 4
# table of contents
add_pages 6..8
add_pages :maybe_add_blank
# preface
add_pages 10..13
add_pages :maybe_add_blank
# chapter 1
add_pages 14..37
add_pages :maybe_add_blank
add_pages 38..44
add_pages :maybe_add_blank
add_pages 54..97
add_pages :maybe_add_blank
add_pages 98..129
add_pages :maybe_add_blank
add_pages 130..186
add_pages :maybe_add_blank
# chapter 6
add_pages 188..225
add_pages :maybe_add_blank
add_pages 226..277
add_pages :maybe_add_blank
add_pages 278..315
add_pages :maybe_add_blank
add_pages 316..401
add_pages :maybe_add_blank
add_pages 402..425
add_pages :maybe_add_blank
# index
add_pages 440..442
add_pages 444
# sudo rm /tmp/magick-*
# ls -hla /tmp/magick-*
d = 300
log "convert -density #{d} #{fname}[#{@pages.join(",")}] ruby_final.pdf"
log "filtered"
end
def blank
9
end
def pages
@pages ||= []
end
def add_pages x
pages
case x
when Integer
@pages.push x
@count += 1
when Range
@pages.push "#{x.min}-#{x.max}"
@count += 1+x.max-x.min
when Symbol
remainder = (@count - 2) % 4
remainder.positive? and (remainder-4).times { add_pages blank }
else
raise "unrecognized type of #{x} : #{x.class}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment