lib/lapidarius/cutter.rb in lapidarius-1.1.4 vs lib/lapidarius/cutter.rb in lapidarius-2.0.1
- old
+ new
@@ -5,12 +5,13 @@
class Cutter
DEVELOPMENT = "development"
class GemNotCreatedError < StandardError; end
- def initialize(gem:, cmd_klass: Command)
+ def initialize(gem:, version: nil, cmd_klass: Command)
@gem = gem
+ @version = version
@cmd = cmd_klass.new
end
def call(src = cmd, gem = nil)
tokens = tokenize(src)
@@ -25,14 +26,18 @@
end
gem
end
private def tokenize(src)
- src = src.split(/\n\n/).first
- src.split("\n").tap do |tokens|
+ data = src.split(/\n\n/).map!(&:strip)
+ by_version(data).split("\n").tap do |tokens|
tokens.map!(&:strip)
tokens.reject! { |token| token.match(/#{DEVELOPMENT}/) }
end
+ end
+
+ private def by_version(data)
+ data.detect { |d| d.match(/^Gem #{@gem}-#{@version}/) } || data.first
end
private def cmd(gem = @gem)
@cmd.call(gem)
end