Class: Smiling::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/smiling/video.rb

Overview

Public: Video represents a video of Nico Nico Douga.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Video

Public: Create an instance of Video.

doc - The Nokogiri::XML::Document contains response of getthumbinfo API.



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
60
# File 'lib/smiling/video.rb', line 29

def initialize(doc)
  thumb = doc.xpath('nicovideo_thumb_response/thumb')
  @id = thumb.xpath('video_id').text
  @title = thumb.xpath('title').text
  @description = thumb.xpath('description').text
  @thumbnail_url = thumb.xpath('thumbnail_url').text
  @first_retrieve = Time.parse(thumb.xpath('first_retrieve').text)
  @length = thumb.xpath('length').text
  @movie_type = thumb.xpath('movie_type').text
  @size_high = thumb.xpath('size_high').text.to_i
  @size_low = thumb.xpath('size_low').text.to_i
  @view_counter = thumb.xpath('view_counter').text.to_i
  @comment_num = thumb.xpath('comment_num').text.to_i
  @mylist_counter = thumb.xpath('mylist_counter').text.to_i
  @last_res_body = thumb.xpath('last_res_body').text
  @watch_url = thumb.xpath('watch_url').text
  @type = thumb.xpath('thumb_type').text
  @embeddable = thumb.xpath('embeddable').text
  @no_live_play = thumb.xpath('no_live_play').text

  @tags = {}
  thumb.xpath('tags').each do |tags|
    domain = tags['domain']
    @tags[domain] = []
    tags.xpath('tag').each do |tag|
      lock = tag['lock'] == '1' ? true : false
      @tags[domain] << Tag.new(value: tag.text, lock: lock)
    end
  end

  @user_id = thumb.xpath('user_id').text.to_i
end

Instance Attribute Details

#comment_numObject (readonly)

Returns the value of attribute comment_num.



16
17
18
# File 'lib/smiling/video.rb', line 16

def comment_num
  @comment_num
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/smiling/video.rb', line 8

def description
  @description
end

#embeddableObject (readonly)

Returns the value of attribute embeddable.



21
22
23
# File 'lib/smiling/video.rb', line 21

def embeddable
  @embeddable
end

#first_retrieveObject (readonly)

Returns the value of attribute first_retrieve.



10
11
12
# File 'lib/smiling/video.rb', line 10

def first_retrieve
  @first_retrieve
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/smiling/video.rb', line 6

def id
  @id
end

#last_res_bodyObject (readonly)

Returns the value of attribute last_res_body.



18
19
20
# File 'lib/smiling/video.rb', line 18

def last_res_body
  @last_res_body
end

#lengthObject (readonly)

Returns the value of attribute length.



11
12
13
# File 'lib/smiling/video.rb', line 11

def length
  @length
end

#movie_typeObject (readonly)

Returns the value of attribute movie_type.



12
13
14
# File 'lib/smiling/video.rb', line 12

def movie_type
  @movie_type
end

#mylist_counterObject (readonly)

Returns the value of attribute mylist_counter.



17
18
19
# File 'lib/smiling/video.rb', line 17

def mylist_counter
  @mylist_counter
end

#no_live_playObject (readonly)

Returns the value of attribute no_live_play.



22
23
24
# File 'lib/smiling/video.rb', line 22

def no_live_play
  @no_live_play
end

#size_highObject (readonly)

Returns the value of attribute size_high.



13
14
15
# File 'lib/smiling/video.rb', line 13

def size_high
  @size_high
end

#size_lowObject (readonly)

Returns the value of attribute size_low.



14
15
16
# File 'lib/smiling/video.rb', line 14

def size_low
  @size_low
end

#tagsObject (readonly)

Returns the value of attribute tags.



23
24
25
# File 'lib/smiling/video.rb', line 23

def tags
  @tags
end

#thumbnail_urlObject (readonly)

Returns the value of attribute thumbnail_url.



9
10
11
# File 'lib/smiling/video.rb', line 9

def thumbnail_url
  @thumbnail_url
end

#titleObject (readonly)

Returns the value of attribute title.



7
8
9
# File 'lib/smiling/video.rb', line 7

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/smiling/video.rb', line 20

def type
  @type
end

#user_idObject (readonly)

Returns the value of attribute user_id.



24
25
26
# File 'lib/smiling/video.rb', line 24

def user_id
  @user_id
end

#view_counterObject (readonly)

Returns the value of attribute view_counter.



15
16
17
# File 'lib/smiling/video.rb', line 15

def view_counter
  @view_counter
end

#watch_urlObject (readonly)

Returns the value of attribute watch_url.



19
20
21
# File 'lib/smiling/video.rb', line 19

def watch_url
  @watch_url
end