=begin (filter/)sum_price_x.rb nDiary Filter 家計簿的数値の作成 金額を書き込んだ.priceファイルを生成します。 plugin/sum_price_x.rbとあわせて利用、ないし別の集計プログラムと利用。 format: .priseファイルは1行1件、TAB区切り date, anchor, title, type, code, price 8桁日付, 日記アンカー, 品名, 品型(book,cd等), 型番(ISBN等), 価格 以上で十分だと思うのですが。 =end class PastDiary attr_reader :cntTopic, :cntParagraph #外から段落アンカーまで拾えるように。それとも別にdefが用意されてたか? end class Filter BOOKSTORE = Regexp::compile(/[\((]ISBN[:|:]?\s?(\d-[\d-]{9}[-]?[\w]?)[\))]/) #BOOKSTOREはbookstoreの上位コンパチの正規表現のはず。二重定義でwarが出るけど消し方判らない AMAZON = Regexp::compile(/[\((]amz:(\d-[\d-]{9}-\w)[\))]/) PRICETAG = Regexp::compile(//) #ex) def sum_price_x(str, type) return if @diary.type != PastDiary #初期化。filter類はDiary(LastDiary,PastDiary)毎に作られるという理解であってるだろうか? オプションallの時等に不安が残る。 unless @flag_initial #initialize @flag_initial = true @expire = 12 @flag_net = @diary.config['nonet'] @filename = @diary.logDirectory + @diary.targetMonth + '.price' File.delete(@filename) if File.exist?(@filename) @flag_tag = true @flag_bookstore_x = true @flag_amazon = false @flag_bookstore = false if @flag_bookstore_x #各自の環境で適時改変 require '../../ruby/simpleuri' require '../../ruby/webagent' require '../../ruby/cache' require '../../ruby/amazon' require '../../ruby/bk1' require '../../ruby/esbooks' require '../../ruby/asahiya' require '../../ruby/jbook' require '../../ruby/kinokuniya' require '../../ruby/skysoft' @cache_amz = "../../bookcache/amz" @cache_bk1 = "../../bookcache/bk1" @cache_esb = "../../bookcache/esb" @cache_ash = "../../bookcache/ash" @cache_jbk = "../../bookcache/jbk" @cache_kin = "../../bookcache/kin" @cache_sky = "../../bookcache/sky" end end case type when :P, :DL, :UL list = [] #-----tag search----- str.scan(PRICETAG){ str = $1 title, type, code, price = '', '', '', '' str.split(/:/).each{ |word| tag, val = word.split(/=/) case tag when 'title' title = val when 'type' type = val when 'code' code = val when 'price' price = val end price = tag if tag =~ /^\\|¥/ price = price.gsub(/[\\|¥|,|円|(税抜)]/,'').strip } list << [title, type, code, price] } if @flag_tag #-----ISBN search (for bookstore.rb)----- str.scan(BOOKSTORE){ isbn = $1 #chache -> price ? title, type, price = '', 'book', '' list << [title, type, isbn, price] } if @flag_bookstore #-----ISBN search (for bookstore_x.rb)----- str.scan(BOOKSTORE){ isbn1 = $1 isbn2 = isbn1.delete('-') checkbook = CacheBib.new() newisbn = checkbook.isbn_check(isbn1) isbn1 = newisbn info = {} book = CacheBib_amazon.new() book.expire = @expire book.cache_dir = @cache_amz ainfo = book.get_data(isbn1, @flag_net) book = CacheBib_bk1.new() book.expire = @expire book.cache_dir = @cache_bk1 binfo = book.get_data(isbn1, @flag_net) book = CacheBib_esbooks.new() book.expire = @expire book.cache_dir = @cache_esb einfo = book.get_data(isbn1, @flag_net) book = CacheBib_asahiya.new() book.expire = @expire book.cache_dir = @cache_ash sinfo = book.get_data(isbn1, @flag_net) book = CacheBib_jbook.new() book.expire = @expire book.cache_dir = @cache_jbk jinfo = book.get_data(isbn1, @flag_net) book = CacheBib_kinokuniya.new() book.expire = @expire book.cache_dir = @cache_kin kinfo = book.get_data(isbn1, @flag_net) book = CacheBib_skysoft.new() book.expire = @expire book.cache_dir = @cache_sky yinfo = book.get_data(isbn1, @flag_net) isbn = isbn1 info = checkbook.merge_info( [ainfo, binfo, einfo, sinfo, jinfo, kinfo, yinfo] ) title, type, price = info['title'], 'book', info['price'] price = price.gsub(/[\\|¥|,|円|(税抜)]/,'').strip list << [title, type, isbn, price] } if @flag_bookstore_x #-----ASIN search (for amazon.rb)----- #未テスト str.scan(AMAZON){ isbn = $1 amz = Amazon::new amz.cache_dir = @diary.logDirectory + 'amzcache' amz.isbn = isbn if @diary.respond_to?('config') then amz.expire = @diary.config['AMAZON_EXPIRE'] || 7 amz.proxy = @diary.config['PROXY'] end title, type, price = amz.title, 'book', amz.price price = price.gsub(/[\\|¥|,|円|(税抜)]/,'').strip list << [title, type, isbn, price] } if @flag_amazon #-----list----- #あれ?cntParagraphがおかしいかな? unless list.empty? anchor = '' if @diary.paragraphAnchor then if @diary.anchorEachTopic then anchor = "_t#{@diary.cntTopic}_#{@diary.cntParagraph+1}" else anchor = "_#{@diary.cntParagraph+1}" end end anchor = "#{@diary.date2monthlyfilelink(@diary.date, true)}#{anchor}" open(@filename, 'a'){ |fp| list.each{ |line| # line.unshift(anchor) # line.unshift(@diary.date) # fp.puts line.join("\t") fp.puts [@diary.date, anchor, *line].join("\t") #出力フォーマットはdate,anchor,title,type,code,priceのTAB区切り } } end end end end