Class: Crown::Hatena::Bookmark::URIList
- Inherits:
-
Object
- Object
- Crown::Hatena::Bookmark::URIList
- Defined in:
- lib/crown/hatena/bookmark/urilist.rb
Overview
--------------------------------------------------------------- #
URIList
指定した Web サイトのはてなブックマーク一覧から順に URL を 取得するクラス.2 ページ目以降の結果は,html のヘッダ情報の next 属性からページの URL を推測して取得する.
--------------------------------------------------------------- #
Direct Known Subclasses
Defined Under Namespace
Classes: Response
Constant Summary collapse
- @@valid_types =
----------------------------------------------------------- # variables ----------------------------------------------------------- #
[ :hotentry, :entrylist, :video, :asin ]
- @@valid_categories =
[ :general, :social, :economics, :life, :entertainment, :knowledge, :it, :game, :fun, :news ]
- @@valid_options =
[ :uri, :sort, :threshold, :offset, :src ]
- @@valid_sorts =
[ :eid, :hot, :count ]
- @@valid_sources =
[ :youtube, :nicovideo, :ugomemo ]
Class Method Summary collapse
-
.start(options = {}, &block) ⇒ Object
----------------------------------------------------------- # URIList.start ----------------------------------------------------------- #.
Instance Method Summary collapse
-
#finish ⇒ Object
----------------------------------------------------------- # finish ----------------------------------------------------------- #.
-
#get ⇒ Object
----------------------------------------------------------- # get ----------------------------------------------------------- #.
-
#initialize(options = {}) ⇒ URIList
constructor
----------------------------------------------------------- # initialize ----------------------------------------------------------- #.
-
#more? ⇒ Boolean
----------------------------------------------------------- #.
-
#proxy_address ⇒ Object
----------------------------------------------------------- # proxy_address ----------------------------------------------------------- #.
-
#proxy_port ⇒ Object
----------------------------------------------------------- # proxy_port ----------------------------------------------------------- #.
-
#reset ⇒ Object
----------------------------------------------------------- # reset ----------------------------------------------------------- #.
-
#start ⇒ Object
----------------------------------------------------------- # start ----------------------------------------------------------- #.
Constructor Details
#initialize(options = {}) ⇒ URIList
----------------------------------------------------------- # initialize ----------------------------------------------------------- #
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 71 def initialize( = {}) proxy_addr = nil proxy_port = nil if (.class == Hash) proxy_addr = [:proxy_address] if (.has_key?(:proxy_address)) proxy_port = [:proxy_port] if (.has_key?(:proxy_port)) end @session = Crown::HTTPWrapper.new('b.hatena.ne.jp', 80, proxy_addr, proxy_port) @basename = basename() @path = String.new(@basename) end |
Class Method Details
.start(options = {}, &block) ⇒ Object
----------------------------------------------------------- # URIList.start ----------------------------------------------------------- #
86 87 88 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 86 def URIList.start( = {}, &block) return URIList.new().start(&block) end |
Instance Method Details
#finish ⇒ Object
----------------------------------------------------------- # finish ----------------------------------------------------------- #
105 106 107 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 105 def finish() @session.finish if (@session.active?) end |
#get ⇒ Object
----------------------------------------------------------- # get ----------------------------------------------------------- #
134 135 136 137 138 139 140 141 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 134 def get() return get_block() if (!block_given?) while (more?) get_block().each { |uri| yield uri } end end |
#more? ⇒ Boolean
----------------------------------------------------------- #
more?
まだ取得できる URL が存在するかどうかを判定する.more?() は html の next 属性から次のページが推測できているか どうかで判定している.
----------------------------------------------------------- #
127 128 129 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 127 def more?() return @path != nil end |
#proxy_address ⇒ Object
----------------------------------------------------------- # proxy_address ----------------------------------------------------------- #
146 147 148 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 146 def proxy_address return @session.proxy_address end |
#proxy_port ⇒ Object
----------------------------------------------------------- # proxy_port ----------------------------------------------------------- #
153 154 155 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 153 def proxy_port return @session.proxy_port end |
#reset ⇒ Object
----------------------------------------------------------- # reset ----------------------------------------------------------- #
112 113 114 115 116 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 112 def reset() @path = String.new(@basename) @session.finish if (@session.active?) return self end |
#start ⇒ Object
----------------------------------------------------------- # start ----------------------------------------------------------- #
93 94 95 96 97 98 99 100 |
# File 'lib/crown/hatena/bookmark/urilist.rb', line 93 def start() @session.start if (!@session.active?) if (block_given?) yield self @session.finish if (@session.active?) end return self end |