Class: Nicos::Mylist
- Inherits:
-
Object
- Object
- Nicos::Mylist
- Includes:
- Connector::SetWait
- Defined in:
- lib/classes/mylist.rb
Instance Attribute Summary collapse
-
#author ⇒ String
作成者の名前.
-
#available ⇒ Boolean
このインスタンスがgetInfo等によって正常に情報を取得できている場合、trueとなる。 各種メソッドの実行には、これがtrueであることが要求される。.
-
#create_time ⇒ Fixnum
マイリスト作成日時.
-
#default_sort ⇒ Fixnum
ソート順の設定.
-
#description ⇒ String
マイリストの説明文.
-
#icon_id ⇒ Fixnum
アイコンの色?.
-
#movies ⇒ Array<Movie>
マイリストが含む動画インスタンスの配列.
-
#mylist_id ⇒ Fixnum
マイリストID.
-
#public ⇒ Fixnum
公開設定.
-
#sort_order ⇒ Fixnum
現在のソート順.
-
#title ⇒ String
マイリストのタイトル.
-
#update_time ⇒ Fixnum
マイリストの更新日時.
-
#user_id ⇒ Fixnum
ユーザID.
Instance Method Summary collapse
-
#getInfo ⇒ Fixnum
マイリストのAtomフィードから、マイリストとそれに含まれる動画の情報を取得する。.
-
#getSimilarity ⇒ Fixnum
自分に含まれている動画のタイトルをすべての組み合わせにおいて比較し、 類似度の平均を返す。.
-
#initialize(mylist_id) ⇒ Mylist
constructor
A new instance of Mylist.
-
#set(paramObj) ⇒ Object
Nicos::Movie#set を参照。.
Methods included from Connector::SetWait
Constructor Details
#initialize(mylist_id) ⇒ Mylist
Returns a new instance of Mylist.
14 15 16 17 18 |
# File 'lib/classes/mylist.rb', line 14 def initialize (mylist_id) @mylist_id = mylist_id @movies = [] @available = false end |
Instance Attribute Details
#author ⇒ String
作成者の名前
取得可能なメソッド Mylist::getInfo
299 300 301 |
# File 'lib/classes/mylist.rb', line 299 def @author end |
#available ⇒ Boolean
このインスタンスがgetInfo等によって正常に情報を取得できている場合、trueとなる。 各種メソッドの実行には、これがtrueであることが要求される。
211 212 213 |
# File 'lib/classes/mylist.rb', line 211 def available @available end |
#create_time ⇒ Fixnum
268 269 270 |
# File 'lib/classes/mylist.rb', line 268 def create_time @create_time end |
#default_sort ⇒ Fixnum
260 261 262 |
# File 'lib/classes/mylist.rb', line 260 def default_sort @default_sort end |
#description ⇒ String
242 243 244 |
# File 'lib/classes/mylist.rb', line 242 def description @description end |
#icon_id ⇒ Fixnum
284 285 286 |
# File 'lib/classes/mylist.rb', line 284 def icon_id @icon_id end |
#movies ⇒ Array<Movie>
マイリストが含む動画インスタンスの配列
getInfo等のメソッドを利用した際に、そのマイリストが含む動画の インスタンスが配列として自動的に作られ、moviesに収められる。
306 307 308 |
# File 'lib/classes/mylist.rb', line 306 def movies @movies end |
#mylist_id ⇒ Fixnum
219 220 221 |
# File 'lib/classes/mylist.rb', line 219 def mylist_id @mylist_id end |
#public ⇒ Fixnum
251 252 253 |
# File 'lib/classes/mylist.rb', line 251 def public @public end |
#sort_order ⇒ Fixnum
292 293 294 |
# File 'lib/classes/mylist.rb', line 292 def sort_order @sort_order end |
#title ⇒ String
234 235 236 |
# File 'lib/classes/mylist.rb', line 234 def title @title end |
#update_time ⇒ Fixnum
276 277 278 |
# File 'lib/classes/mylist.rb', line 276 def update_time @update_time end |
#user_id ⇒ Fixnum
ユーザID
取得可能なメソッド Mylist::getHtmlInfo
226 227 228 |
# File 'lib/classes/mylist.rb', line 226 def user_id @user_id end |
Instance Method Details
#getInfo ⇒ Fixnum
マイリストのAtomフィードから、マイリストとそれに含まれる動画の情報を取得する。
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/classes/mylist.rb', line 151 def getInfo parsed = nil @available = false con = Nicos::Connector::MylistAtom.new() host = 'www.nicovideo.jp' entity = '/mylist/' + @mylist_id.to_s + '?rss=atom&numbers=1' result = con.get(host, entity) status = con.getStatus if result[:order] == :afterTheSuccess parsed = Nicos::Parser::mylistAtom(result[:body]) parsed[:entry].each { |e| movie = Nicos::Movie.new(e[:video_id]) e[:available] = true movie.set(e) @movies.push(movie) } set(parsed[:mylist]) @available = true end { :parsed => parsed, :status => status[:status], :retry => status[:retry] } end |
#getSimilarity ⇒ Fixnum
自分に含まれている動画のタイトルをすべての組み合わせにおいて比較し、 類似度の平均を返す。
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/classes/mylist.rb', line 24 def getSimilarity l = @movies.length - 1 dlc = DamerauLevenshtein dl = 0.0 dlAry = [] count_o = 0 count_i = 0 while count_o <= l do count_i = count_o + 1 while count_i <= l do dl = dlc.distance( @movies[count_i].title, @movies[count_o].title ) dl = 1.0 - dl.fdiv( @movies[count_i].title.length) dlAry.push(dl) count_i += 1 end count_o += 1 end if l != 0 && dlAry.length > 0 t = 0 dlAry.each { |_dl| t += _dl } similarity = t / dlAry.length elsif dlAry.length == 0 similarity = 0 else similarity = 1 end return similarity end |
#set(paramObj) ⇒ Object
Nicos::Movie#set を参照。
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/classes/mylist.rb', line 184 def set(paramObj) paramObj.each_key do |key| param = paramObj[key] case key when "mylist_id", :mylist_id then @mylist_id = param when "user_id", :user_id then @user_id = param when "title", :title then @title = param when "description",:description then @description = param when "public", :public then @public = param when "default_sort",:default_sort then @default_sort = param when "create_time",:create_time then @create_time = param when "update_time",:updated_time then @update_time = param when "icon_id", :icon_id then @icon_id = param when "sort_order", :sort_order then @sort_order = param when "movies", :movies then @movies = param when "updated", :updated then @update_time = param when "author", :author then @author = param end end end |