Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions 19 lib/docsplit/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def parse_options
opts.on('-o', '--output [DIR]', 'set the directory for all output') do |d|
@options[:output] = d
end
opts.on('-p', '--pages [PAGES]', "extract specific pages (eg: 5-10)") do |p|
@options[:pages] = p
opts.on('-p', '--pages [PAGES]', "extract specific pages (eg: 5-10 or 1,3,5)") do |p|
@options[:pages] = self.class.format_page_param(p)
end
opts.on('-s', '--size [SIZE]', 'set a fixed size (eg: 50x75)') do |s|
@options[:size] = s.split(',')
Expand Down Expand Up @@ -120,6 +120,19 @@ def parse_options
end
end

def self.format_page_param(pages_arg)
numbers_and_ranges = pages_arg.to_s.scan(/[\d\-]+/)
output = numbers_and_ranges.collect {|page_arg|
if page_arg.include?("-")
Range.new(*page_arg.split("-")).to_a
else
page_arg
end
}

output.flatten.uniq.map(&:to_i).sort
end

end

end
end
25 changes: 25 additions & 0 deletions 25 test/unit/test_command_line.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
here = File.expand_path(File.dirname(__FILE__))
require File.join(here, '..', 'test_helper')
require "#{Docsplit::ROOT}/lib/docsplit/command_line"

class ConvertToPdfTest < Minitest::Test

def test_page_cli_parsing
input = "1,3-6,9,12,2,3"
output = Docsplit::CommandLine.format_page_param(input)
assert_equal [1,2,3,4,5,6,9,12], output

input = "3"
output = Docsplit::CommandLine.format_page_param(input)
assert_equal [3], output

input = "3-6"
output = Docsplit::CommandLine.format_page_param(input)
assert_equal [3, 4, 5, 6], output

input = "2,4,6,8"
output = Docsplit::CommandLine.format_page_param(input)
assert_equal [2, 4, 6, 8], output
end

end
Morty Proxy This is a proxified and sanitized view of the page, visit original site.