Class: SleipnirAPI::Profile::Section

Inherits:
ProfileElement show all
Defined in:
lib/sleipnir_api/profile/section.rb

Overview

ini ファイルのセクションに対応するオブジェクトです。このオブジェクトは SleipnirAPI::Profile::Ini#section で取得します。

pnir = SleipnirAPI.new
ini = pnir.profile("CloseURL.ini")
sec = ini.section("ClosedURL2")
sec.get_string("URL0")  #=> "http://hogehoge"

#key でこのセクション内のキーに対応する SleipnirAPI::Profile::Key オブジェクトを取得できます。

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ProfileElement

#inspect, #nodes, #parents

Methods included from DataUtil

#check_data, #str

Methods included from OptionArgument

#options

Methods included from OptionUtil

parse_option_arguments

Constructor Details

#initialize(parent, name, default_opts = nil) ⇒ Section

Returns a new instance of Section.



35
36
37
38
# File 'lib/sleipnir_api/profile/section.rb', line 35

def initialize(parent, name, default_opts = nil)
  super(parent, default_opts)
  @name = name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mid, *args, &block) ⇒ Object

メソッド名をキー名とみなして SleipnirAPI::Profile::Key オブジェクトを返します。

pnir = SleipnirAPI.connect
proxy = pnir.profile.Proxy(:default => 123)
sec = proxy.Proxy
key = sec.Count
key.get_int

See Also: #key



141
142
143
# File 'lib/sleipnir_api/profile/section.rb', line 141

def method_missing(mid, *args, &block)
  key(mid.to_s, *args, &block)
end

Instance Attribute Details

#default_optsObject (readonly)

#get_string などに指定するデフォルトの引数を取得します。値は #parent から引き継いでいます。



33
34
35
# File 'lib/sleipnir_api/profile/section.rb', line 33

def default_opts
  @default_opts
end

#nameObject (readonly) Also known as: to_s

セクション名を返します。



26
27
28
# File 'lib/sleipnir_api/profile/section.rb', line 26

def name
  @name
end

#parentObject (readonly) Also known as: ini

SleipnirAPI::Profile::Ini オブジェクトを返します



20
21
22
# File 'lib/sleipnir_api/profile/section.rb', line 20

def parent
  @parent
end

Instance Method Details

#delete(key) ⇒ Object

このセクションの指定されたキーを削除します。script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。

See Also: SleipnirAPI::Profile#delete



115
116
117
# File 'lib/sleipnir_api/profile/section.rb', line 115

def delete(key)
  @parent.delete(@name, key)
end

#get_int(key, opts = nil) ⇒ Object

call-seq:

get_int(key)
get_int(key, :default => -1)
get_int(key, :cipher => true)
get_int(key, :cipher => true, :default => -1)

このセクションの指定されたキーを取得します。

See Also: SleipnirAPI::Profile#get_int



83
84
85
# File 'lib/sleipnir_api/profile/section.rb', line 83

def get_int(key, opts = nil)
  @parent.get_int(@name, key, options(opts))
end

#get_string(key, opts = nil) ⇒ Object Also known as: []

call-seq:

get_string(key)
get_string(key, :default => -1)
get_string(key, :cipher => true)
get_string(key, :cipher => true, :default => -1)

このセクションの指定されたキーを取得します。

See Also: SleipnirAPI::Profile#get_string



69
70
71
# File 'lib/sleipnir_api/profile/section.rb', line 69

def get_string(key, opts = nil)
  @parent.get_string(@name, key, options(opts))
end

#key(name, opts = nil) ⇒ Object

キーを操作する SleipnirAPI::Profile::Key オブジェクトを返します。

pnir = SleipnirAPI.connect
proxy = pnir.profile.ini("Proxy.ini", :default => 123)
sec = proxy.section("Proxy")
key = sec.key("Count")
key.get_int

See Also: #method_missing



128
129
130
# File 'lib/sleipnir_api/profile/section.rb', line 128

def key(name, opts = nil)
  Key.new(self, str(name), options(opts))
end

#list(keyformat, countkey = "Count", opts = nil, &block) ⇒ Object

call-seq:

list(keyfmt, countkey="Count")
list(keyfmt, countkey="Count", :default => "default value")
list(keyfmt, countkey="Count", :cipher => true)
list(keyfmt, countkey="Count", :cipher => true, :default => "default value")

このセクションから連番キーのデータをすべて読み込み配列で返します。

例:

pnir = SleipnirAPI.connect
proxy_ini = pnir.profile.proxy
proxy_sec = proxy_ini.Proxy
proxy_sec.list("Proxy0_Title")

See Also: SleipnirAPI::Profile#list



56
57
58
# File 'lib/sleipnir_api/profile/section.rb', line 56

def list(keyformat, countkey = "Count", opts = nil, &block)
  @parent.list(@name, keyformat, countkey, options(opts), &block)
end

#write_int(key, data, opts = nil) ⇒ Object

call-seq:

write_int(key, data)
write_int(key, data, :cipher => true)

このセクションの指定されたキーを書き込みます。script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。

See Also: SleipnirAPI::Profile#write_int



107
108
109
# File 'lib/sleipnir_api/profile/section.rb', line 107

def write_int(key, data, opts = nil)
  @parent.write_int(@name, key, data, options(opts))
end

#write_string(key, data, opts = nil) ⇒ Object

call-seq:

write_string(key, data)
write_string(key, data, :cipher => true)

このセクションの指定されたキーを書き込みます。script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。

See Also: SleipnirAPI::Profile#write_string



95
96
97
# File 'lib/sleipnir_api/profile/section.rb', line 95

def write_string(key, data, opts = nil)
  @parent.write_string(@name, key, data, options(opts))
end