Class: SleipnirAPI::Profile::Key

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

Overview

ini ファイルのキーに対応するオブジェクトです。このオブジェクトは SleipnirAPI::Profile::Section#key で取得します。

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

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) ⇒ Key

Returns a new instance of Key.



31
32
33
34
# File 'lib/sleipnir_api/profile/key.rb', line 31

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

Instance Attribute Details

#default_optsObject (readonly)

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



29
30
31
# File 'lib/sleipnir_api/profile/key.rb', line 29

def default_opts
  @default_opts
end

#nameObject (readonly)

キー名を返します。



25
26
27
# File 'lib/sleipnir_api/profile/key.rb', line 25

def name
  @name
end

#parentObject (readonly) Also known as: section

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



19
20
21
# File 'lib/sleipnir_api/profile/key.rb', line 19

def parent
  @parent
end

Instance Method Details

#deleteObject

このキーを削除します。script.ini でない場合は SleipnirAPI::Profile::ReadOnlyError を raise します。

See Also: SleipnirAPI::Profile#delete



114
115
116
# File 'lib/sleipnir_api/profile/key.rb', line 114

def delete
  @parent.delete(name)
end

#get_int(opts = nil) ⇒ Object Also known as: to_i

call-seq:

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

このキーの int 値を取得します。

See Also: SleipnirAPI::Profile#get_int



81
82
83
# File 'lib/sleipnir_api/profile/key.rb', line 81

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

#get_string(opts = nil) ⇒ Object Also known as: to_s

call-seq:

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

このキーの string 値を取得します。

See Also: SleipnirAPI::Profile#get_string



67
68
69
# File 'lib/sleipnir_api/profile/key.rb', line 67

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

#list(countkey = "Count", opts = nil, &block) ⇒ Object Also known as: to_a

call-seq:

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

このキーから連番キーを生成して、連番データをすべて読み込み配列で返します。

例:

pnir = SleipnirAPI.connect
proxy_ini = pnir.profile.proxy
proxy_sec = proxy_ini.Proxy
proxy_title = proxy_sec.Proxy0_Title
proxy_title.list

See Also: SleipnirAPI::Profile#list



53
54
55
# File 'lib/sleipnir_api/profile/key.rb', line 53

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

#write_int(data, opts = nil) ⇒ Object

call-seq:

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

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

See Also: SleipnirAPI::Profile#write_int



106
107
108
# File 'lib/sleipnir_api/profile/key.rb', line 106

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

#write_string(data, opts = nil) ⇒ Object

call-seq:

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

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

See Also: SleipnirAPI::Profile#write_string



94
95
96
# File 'lib/sleipnir_api/profile/key.rb', line 94

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