Skip to content

Instantly share code, notes, and snippets.

@masao
Last active December 20, 2020 08:52
Show Gist options
  • Save masao/1f15428c0e1023ec2db85b3876b653b1 to your computer and use it in GitHub Desktop.
Save masao/1f15428c0e1023ec2db85b3876b653b1 to your computer and use it in GitHub Desktop.
所蔵式 HLV の巻情報を展開する
class String
def expand_hlv
self.gsub(/\([^\)]+\)/, "").split(/;/).map do |e1|
e1.split(/,\s*/).map do |e|
start_vol, end_vol, = e.gsub(/\+/, "").split(/-/)
if end_vol
(start_vol .. end_vol).to_a
else
start_vol
end
end
end.flatten
end
end
if $0 == __FILE__
p "40-80".expand_hlv
p "60,7-8".expand_hlv
p "6(6),7(2-4),8(1-4)".expand_hlv
p "7-8,9(1-7,9-12),10-16".expand_hlv
p "4-9;5-8".expand_hlv
p "4-9;5-7,8(1-4)".expand_hlv
p "159-170;16-18,19(1-2,4-6,8-12),20-21".expand_hlv
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment