クラス
- CSV (33)
-
JSON
:: Parser (22) -
Net
:: HTTPGenericRequest (22) -
Net
:: HTTPResponse (44) - Object (26)
モジュール
-
OpenURI
:: OpenRead (11)
キーワード
- body (11)
-
body
_ stream (11) -
body
_ stream= (11) - convert (33)
- entity (11)
-
read
_ body (22) - source (11)
- then (12)
-
yield
_ self (14)
検索結果
先頭5件
-
OpenURI
:: OpenRead # read(options = {}) -> String (21130.0) -
自身が表す内容を読み込んで文字列として返します。 self.open(options={}) {|io| io.read } と同じです。 このメソッドによって返される文字列は OpenURI::Meta によって extend されています。
...ons={}) {|io| io.read } と同じです。
このメソッドによって返される文字列は OpenURI::Meta
によって extend されています。
@param options ハッシュを与えます。
require 'open-uri'
uri = URI.parse('http://www.example.com/')
str = uri.read
p str.is_a?(O... -
JSON
:: Parser # parse -> object (21114.0) -
現在のソースをパースして結果を Ruby のオブジェクトとして返します。
...[]=(key, value)
instance_variable_set("@#{key}", value)
end
end
parser = JSON::Parser.new(DATA.read, object_class: Person)
person = parser.parse
person.class # => Person
person.name # => "tanaka"
person.age # => 20
__END__
{
"name":"tanaka",
"age":20
}
//}
@see JSON::Parser#source... -
Net
:: HTTPResponse # read _ body {|str| . . . . } -> () (6133.0) -
ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。
....example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.read_body[0..10] # => "<!doctype h"
//}
//emlist[例2 ブロックを与えて大きいファイルを取得][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/path/to/big.file')
Net::HTTP.start(uri......"/path/to/big.file", "w") do |f|
# Net::HTTP#request_get と Net::HTTPResponse#read_body で少しずつ読み書き。メモリ消費が少ない。
http.request_get(uri.path) do |response|
response.read_body do |s|
f.write(s)
end
end
end
end
//}
一度ブロッ......ボディを文字列として
返します。また一度ブロックを与えてこのメソッドを呼んだ場合には、
次からは Net::ReadAdapter のインスタンスが返ってきますが、
その場合はそのオブジェクトは使わないでください。
dest は obsolete... -
Net
:: HTTPResponse # read _ body(dest=nil) -> String|nil (6133.0) -
ブロックを与えなかった場合にはエンティティボディを 文字列で返します。 ブロックを与えた場合には エンティティボディを少しずつ取得して順次ブロックに 文字列で与えます。
....example.com/index.html"
response = Net::HTTP.get_response(URI.parse(uri))
response.read_body[0..10] # => "<!doctype h"
//}
//emlist[例2 ブロックを与えて大きいファイルを取得][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/path/to/big.file')
Net::HTTP.start(uri......"/path/to/big.file", "w") do |f|
# Net::HTTP#request_get と Net::HTTPResponse#read_body で少しずつ読み書き。メモリ消費が少ない。
http.request_get(uri.path) do |response|
response.read_body do |s|
f.write(s)
end
end
end
end
//}
一度ブロッ......ボディを文字列として
返します。また一度ブロックを与えてこのメソッドを呼んだ場合には、
次からは Net::ReadAdapter のインスタンスが返ってきますが、
その場合はそのオブジェクトは使わないでください。
dest は obsolete... -
JSON
:: Parser # source -> String (3007.0) -
現在のソースのコピーを返します。
...現在のソースのコピーを返します。
//emlist[例][ruby]{
require 'json'
parser = JSON::Parser.new(DATA.read)
print parser.source
# => {
# => "Tanaka": {
# => "name":"tanaka",
# => "age":20
# => },
# => "Suzuki": {
# => "name":"suzuki",
# => "age":25
# => }
#... -
Net
:: HTTPGenericRequest # body _ stream -> object (23.0) -
サーバに送るリクエストのエンティティボディを IO オブジェクトなどのストリームで設定します。 f は read(size) メソッドが定義されている必要があります。
...ムで設定します。
f は read(size) メソッドが定義されている必要があります。
@param f エンティティボディのデータを得るストリームオブジェクトを与えます。
//emlist[例][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/index... -
Net
:: HTTPGenericRequest # body _ stream=(f) (23.0) -
サーバに送るリクエストのエンティティボディを IO オブジェクトなどのストリームで設定します。 f は read(size) メソッドが定義されている必要があります。
...ムで設定します。
f は read(size) メソッドが定義されている必要があります。
@param f エンティティボディのデータを得るストリームオブジェクトを与えます。
//emlist[例][ruby]{
require 'net/http'
uri = URI.parse('http://www.example.com/index... -
CSV
# convert {|field , field _ info| . . . } (13.0) -
引数 name で指定した変換器かブロックに各フィールドを渡して文字列から別 のオブジェクトへと変換します。
...す。
//emlist[例 name で Converter を指定][ruby]{
require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10")
csv.convert(:date)
csv.read # => 2018-07-09 ((2458309j,0s,0n),+0s,2299161j)>, #<Date: 2018-07-10 ((2458310j,0s,0n),+0s,2299161j)>
//}
//emlist[例 ブロックを指定][rub......require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10", headers: true)
csv.convert do |field,field_info|
p field
p field_info
Date.parse(field)
end
p csv.first
# => "2018-07-09"
# => <struct CSV::FieldInfo index=0, line=2, header="date1">
# => "2018-07-10"
# => #<struct CSV::FieldI... -
CSV
# convert {|field| . . . } (13.0) -
引数 name で指定した変換器かブロックに各フィールドを渡して文字列から別 のオブジェクトへと変換します。
...す。
//emlist[例 name で Converter を指定][ruby]{
require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10")
csv.convert(:date)
csv.read # => 2018-07-09 ((2458309j,0s,0n),+0s,2299161j)>, #<Date: 2018-07-10 ((2458310j,0s,0n),+0s,2299161j)>
//}
//emlist[例 ブロックを指定][rub......require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10", headers: true)
csv.convert do |field,field_info|
p field
p field_info
Date.parse(field)
end
p csv.first
# => "2018-07-09"
# => <struct CSV::FieldInfo index=0, line=2, header="date1">
# => "2018-07-10"
# => #<struct CSV::FieldI... -
CSV
# convert(name) (13.0) -
引数 name で指定した変換器かブロックに各フィールドを渡して文字列から別 のオブジェクトへと変換します。
...す。
//emlist[例 name で Converter を指定][ruby]{
require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10")
csv.convert(:date)
csv.read # => 2018-07-09 ((2458309j,0s,0n),+0s,2299161j)>, #<Date: 2018-07-10 ((2458310j,0s,0n),+0s,2299161j)>
//}
//emlist[例 ブロックを指定][rub......require "csv"
csv = CSV.new("date1,date2\n2018-07-09,2018-07-10", headers: true)
csv.convert do |field,field_info|
p field
p field_info
Date.parse(field)
end
p csv.first
# => "2018-07-09"
# => <struct CSV::FieldInfo index=0, line=2, header="date1">
# => "2018-07-10"
# => #<struct CSV::FieldI...