# coding: Shift_JIS
# 012345678901234567890
indata = [
"A001YAMADA 080",
"B001TANAKA 065",
"A010YAMAMOTO 079",
"B004UETA 049",
"C032ANDO 095",
"D002KOMATSU 060"
]
def analyze(str)
str.gsub!(/(\d+),(\d+)/, 's[\1,\2]')
str.gsub!(/,CH/, '')
# str.gsub!(/,(ZD|PD)/, '.\1to_i')
str.gsub!(/,(ZD|PD)/, '.to_i')
str.gsub!(/,EQ,/, ' == ')
str.gsub!(/,NE,/, ' != ')
str.gsub!(/,GE,/, ' >= ')
str.gsub!(/,GT,/, ' > ')
str.gsub!(/,LE,/, ' <= ')
str.gsub!(/,LT,/, ' < ')
str.gsub!(/,AND,/, ' && ')
str.gsub!(/,OR,/, ' || ')
puts str
return str
end
#抽出条件例
# (Aクラス かつ 80点以上)または(Bクラス かつ 50点以上)または(Cクラス)を抽出
parm = '(0,1,CH,EQ,"A",AND,14,3,ZD,GE,80),OR,(0,1,CH,EQ,"B",AND,14,3,ZD,GE,50),OR,(0,1,CH,EQ,"C")'
siki = analyze(parm)
indata.each{|s|
if eval siki
p s
end
}
IyBjb2Rpbmc6IFNoaWZ0X0pJUwogCiAKIyAgICAwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAKaW5kYXRhID0gWwoJIkEwMDFZQU1BREEgICAgMDgwIiwKCSJCMDAxVEFOQUtBICAgIDA2NSIsCgkiQTAxMFlBTUFNT1RPICAwNzkiLAoJIkIwMDRVRVRBICAgICAgMDQ5IiwKCSJDMDMyQU5ETyAgICAgIDA5NSIsCgkiRDAwMktPTUFUU1UgICAwNjAiCl0KCgpkZWYgYW5hbHl6ZShzdHIpCgogIHN0ci5nc3ViISgvKFxkKyksKFxkKykvLCAnc1tcMSxcMl0nKQogIHN0ci5nc3ViISgvLENILywgJycpCiMgIHN0ci5nc3ViISgvLChaRHxQRCkvLCAnLlwxdG9faScpCiAgc3RyLmdzdWIhKC8sKFpEfFBEKS8sICcudG9faScpCiAgc3RyLmdzdWIhKC8sRVEsLywgJyA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