緑のボタンを押せ! 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.05.06
XML
テーマ: 私のPC生活(7590)
カテゴリ: Ruby
2009/6/29 さらに 直しました
まえにも、書いたんですが、ちょっと直しました。

ini = IniFile.new( "test.ini")

で、ハッシュのハッシュを返します。

ini[ section ][ key ]

でセクション、キーで値を参照できます。存在しない、ハッシュ、キーが指定されると""(ヌル文字列)が返ります。


ini[ section ]

でセクション全体をハッシュとして返します。存在しないセクションを指定すれば、空のハッシュを返します。

iniファイルを書く方も作らなければなりませんね。ま、それはまた今度。


#
# (c)2009 BO
#
class IniFile < Hash
  @@ReComment = /^#/
  @@ReSection =/\[\s*(.*)\s*\]/
  @@ReKeyValue =/\s*(.*)\s*=\s*(.*)\s*/
  def initialize( fileSpec )
    @fileSpec = fileSpec
    File::open( fileSpec) {|f|
      sName = ""
      tmpHash = Hash::new
      tmpHash.default = ""
      while line = f.gets
        if line =~ @@ReComment
        elsif line =~ @@ReSection
          # closing previous section
          if sName != ""
            self[ sName ]= tmpHash
          end # if
          sName = $1.strip
          if ( tmpHash = self[ sName ] ) == nil
            tmpHash = Hash::new
            tmpHash.default = ""
          end
        elsif line =~ @@ReKeyValue
          tmpHash[ $1.strip  ] = $2.strip
        end
      end # while
      # closing final section
      if sName != ""
        self[ sName ]= tmpHash
      end # if
    }
    tmpHash = Hash::new
    tmpHash.default = ""
    self.default = tmpHash
    self
  end #def initialize( fileSpec )

  attr_reader :fileSpec
end # class IniFile







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

Last updated  2009.06.28 18:48:44
コメント(6) | コメントを書く
[Ruby] カテゴリの最新記事


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

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