Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
電子部品通販サイトで買い物した時の【ご注文明細】を Markdown のチェックリスト化する
#!/usr/bin/env ruby
if __FILE__ == $0
while line = gets do
case line
when /^○ +/
m = Regexp.last_match
s = m.post_match.chomp
break if s == 'お客様情報'
print line, "\n"
when /\[商品名\](.+)[[:blank:]]{2,}[0-9,]+ 円 x[[:blank:]]*([0-9]+)[[:blank:]]{2,}[0-9,]+ 円/
m = Regexp.last_match
s = m[1]
n = m[2].to_i
print "- [ ] #{s}\n"
print " **× #{n}**\n" if 1 < n
end
end
end
#!/usr/bin/env ruby
def to_half(s)
s.tr('0-9a-zA-Z ', '0-9a-zA-Z ')
end
if __FILE__ == $0
sub = false
n = 0
while /^-----/ !~ gets do
end
while line = gets do
case line
when /^【(.+)】/
sub = false
m = Regexp.last_match
print "\n" if 0 < n
print line, "\n"
sub = true if m[1] == 'お買上金額'
when /^[[:blank:]]*([0-9]+)\./
sub = false
m = Regexp.last_match
n = m[1].to_i
printf "- [ ] %s", to_half(m.post_match)
when /^[[:blank:]]+価格:.+数量:([0-9]+) /
m = Regexp.last_match
n = m[1].to_i
print " **× #{n}**\n" if 1 < n
when /^[[:blank:]]+(.+)/
s = Regexp.last_match[1]
print "* #{s}\n" if sub
when /^-----/
break
end
end
end
#!/usr/bin/env ruby
VISIBLES = {
code: false,
plice: false,
}
if __FILE__ == $0
while line = gets do
case line
when /^ご注文番号:/
print line, "\n"
when /^(商品名|商 品 名)[[:blank:]]*(?<name>.+)/
m = Regexp.last_match
s = m[:name]
print "- [ ] #{s}\n"
when /^商品コード:(?<code>.+)(商品番号:(?<no>[0-9]+))/
next unless VISIBLES[:code]
m = Regexp.last_match
s, n = m[:code], m[:no]
print " #{s}(商品番号:#{n}\n"
when /^(単価|単品価格)[[:blank:]]*:[[:blank:]]*¥[[:blank:]]*(?<plice>[0-9,]+)/
next unless VISIBLES[:plice]
m = Regexp.last_match
n = m[:plice].to_i
print "#{n}\n"
when /^数量[[:blank:]]*:[[:blank:]]*(?<unit>[0-9,]+)/
m = Regexp.last_match
n = m[:unit].to_i
print " **× #{n}**\n" if 1 < n
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment