Class: Crown::Hatena::Bookmark::URIList

Inherits:
Object
  • Object
show all
Defined in:
lib/crown/hatena/bookmark/urilist.rb

Overview

————————————————————— #

URIList

指定した Web サイトのはてなブックマーク一覧から順に URL 
取得するクラス.2 ページ目以降の結果は,html のヘッダ情報の
next 属性からページの URL を推測して取得する.

————————————————————— #

Direct Known Subclasses

EntryList

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

Instance Method Summary collapse

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(options = {})
    proxy_addr = nil
    proxy_port = nil
    if (options.class == Hash)
        proxy_addr = options[:proxy_address] if (options.has_key?(:proxy_address))
        proxy_port = options[:proxy_port] if (options.has_key?(:proxy_port))
    end
    @session = Crown::HTTPWrapper.new('b.hatena.ne.jp', 80, proxy_addr, proxy_port)
    @basename = basename(options)
    @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(options = {}, &block)
    return URIList.new(options).start(&block)
end

Instance Method Details

#finishObject

———————————————————– #

finish

———————————————————– #



105
106
107
# File 'lib/crown/hatena/bookmark/urilist.rb', line 105

def finish()
    @session.finish if (@session.active?)
end

#getObject

———————————————————– #

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 属性から次のページが推測できているか
どうかで判定している.

———————————————————– #

Returns:

  • (Boolean)


127
128
129
# File 'lib/crown/hatena/bookmark/urilist.rb', line 127

def more?()
    return @path != nil
end

#proxy_addressObject

———————————————————– #

proxy_address

———————————————————– #



146
147
148
# File 'lib/crown/hatena/bookmark/urilist.rb', line 146

def proxy_address
    return @session.proxy_address
end

#proxy_portObject

———————————————————– #

proxy_port

———————————————————– #



153
154
155
# File 'lib/crown/hatena/bookmark/urilist.rb', line 153

def proxy_port
    return @session.proxy_port
end

#resetObject

———————————————————– #

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

#startObject

———————————————————– #

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