緑のボタンを押せ! Press the green button

緑のボタンを押せ! Press the green button

PR

×

Keyword Search

▼キーワード検索

Archives

2026.10
2026.09
2026.08
2026.07
2026.06

Comments

effelpist@ kilovermek.es effelpist &lt;a href=&quot; <small> <a href="http…
Jun@ Re:「いっちゅう」さんのiEPG用ソフト入れてみた(09/15) TVdeIEPG Ver.1.2.1.0がリンク切れしてい…
スター@ Re:hauppauge HD PVR 速報(08/25) スタービーチ <small> <a href="http://c…
ASOBO@ Re:hauppauge HD PVR 速報 ASOBO攻略 <small> <a href="http:/…
ハッピーメール@ Re:hauppauge HD PVR 速報 ハッピーメール <small> <a href="http:/…

Freepage List

Favorite Blog

まだ登録されていません
2009.07.03
XML
テーマ: 私のPC生活(7590)
カテゴリ: PVR
録画の予約を管理するためのデータベースです。デバッグが楽になるかと思い、ディレクトリ(データベース)にiEPGデータをファイル形式で入れてあります。ファイル名がキーになっているハッシュみたいな感じ。あとでちゃんとしたデータベースエンジンを利用する方がいいでしょうね。
当初は、録画の予約時間順にデータが取り出せればよいと思っていたので、キューみたいなものを想定していたのですが、録画予約の確認のためにはソートした一覧とかが必要で、むしろArrayに近いI/Fになっています。

参考、Rubyで利用できるデータベース機能
http://www.gesource.jp/programming/ruby/database/index.html
----

# Class ReserveDB (C)2009 B.O.
#  refer below for MonitorMixin
#    http://www.ruby-lang.org/ja/man/html/MonitorMixin.html
require( "monitor")
require( "IEPGD")
require( 'to_WinFileName' )

class ReserveDB
  include To_WinFileName
  include Enumerable
  @@EXT = "tvpid"

  def initialize( workFolder )
    @workFolder = File::expand_path( workFolder)
    self.extend(MonitorMixin)
    if ! FileTest::directory?( @workFolder)
      Dir::mkdir( @workFolder )
    end
  end #def initialize

  def to_s
    "ReserveDB[#{@workFolder}]"
  end #def to_s

  def clear
    synchronize {
      Dir::glob( "#{@workFolder}/*.#{@@EXT}").each {|f|
        File.delete( f )
      }
    }
  end #def clear

  def length
    to_a().length()
  end # def length

  def empty?
    length() == 0
  end #def empty?

  # adding an iEPGD data
  # needs to check if the same program has existed already
  def push( iEPGo )
    synchronize {
      del( iEPGo)
      fname = iEPGo.to_s("%D__%T_%eT_%program-title:_%station-name:_%station:" )
      fname = to_WinFileName(fname )
      fname += ".#{@@EXT}"
      fh = File.open("#{@workFolder}/#{fname}",'w')
      fh.puts( iEPGo.to_s )
      fh.close
    }
  end # def push( iEPG )

  # delete
  # if successful, returns true
  # if not returns nil
  def del( iEPGo )
    ret = false
    # gather all data in the DB
    synchronize {
      Dir::glob( "#{@workFolder}/*.#{@@EXT}").each {|f|
        if (arrayiEPG= IEPG.File2Array( f))
          if arrayiEPG[0].sameProgram?( iEPGo )
            File.delete( f )
            ret = true
          end
        end
      }
    }
    ret
  end # def _del( oiEPG )

  def to_a
    ar = Array.new
    synchronize {
      # gather all data in the DB
      Dir::glob( "#{@workFolder}/*.#{@@EXT}").each {|f|
        if (arrayiEPG= IEPG.File2Array( f))
            ar += arrayiEPG
        end
      }
    }
    ar
  end #def to_a

  def each
    ar = to_a
    ar.each{|prof|
        yield(prof)    
    }
  end # def each

  def top()
    min()
  end # def top

  def pop
    synchronize {
      if (tmp = top())
        del( tmp )
        return tmp
      else
        return nil
      end
    }
  end #def pop

end # class ReserveDB






お気に入りの記事を「いいね!」で応援しよう

Last updated  2009.07.03 07:04:27
コメント(0) | コメントを書く


【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! -- / --
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x
X

© Rakuten Group, Inc.
X
Design a Mobile Site
スマートフォン版を閲覧 | PC版を閲覧
Share by: