Class: NicoQuery::ObjectMapper::GetThumbInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/nicoquery/object_mapper/getthumbinfo.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ GetThumbInfo

Returns a new instance of GetThumbInfo.



8
9
10
11
12
13
14
15
16
17
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 8

def initialize(xml)
  @xml = xml
  @parser = Nori.new
  @parsed_xml = @parser.parse xml

  @hash = @parsed_xml['nicovideo_thumb_response']['thumb']
  if !exist?
    @hash = @parser.parse null_xml
  end
end

Instance Method Details

#comment_numObject



98
99
100
101
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 98

def comment_num
  return nil if @hash == nil
  @hash['comment_num'].to_i
end

#community?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 27

def community?
  if @parsed_xml['nicovideo_thumb_response']["error"].presence
    @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence == "COMMUNITY"
  else
    false
  end
end

#deleted?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 19

def deleted?
  if @parsed_xml['nicovideo_thumb_response']["error"].presence
    @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence == "DELETED"
  else
    false
  end
end

#descriptionObject



53
54
55
56
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 53

def description
  return nil if @hash.nil? || @hash['description'].nil?
  @_description ||= Description.new @hash['description']
end

#embeddableObject



128
129
130
131
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 128

def embeddable
  return nil if @hash == nil
  @hash['embeddable'] == 1
end

#exist?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 35

def exist?
  if @parsed_xml['nicovideo_thumb_response']["error"].presence
    @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence != "NOT_FOUND"
  else
    true
  end
end

#first_retrieveObject



63
64
65
66
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 63

def first_retrieve
  return nil if @hash == nil
  @hash['first_retrieve'].to_time
end

#last_res_bodyObject



108
109
110
111
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 108

def last_res_body
  return nil if @hash == nil
  @hash['last_res_body']
end

#lengthObject



72
73
74
75
76
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 72

def length
  return nil if @hash == nil
  string = @hash['length'].split(':')
  string[0].to_i * 60 + string[1].to_i
end

#movie_typeObject



78
79
80
81
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 78

def movie_type
  return nil if @hash == nil
  @hash['movie_type']
end

#mylist_counterObject



103
104
105
106
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 103

def mylist_counter
  return nil if @hash == nil
  @hash['mylist_counter'].to_i
end

#no_live_playObject



133
134
135
136
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 133

def no_live_play
  return nil if @hash == nil
  @hash['no_live_play'] == 1
end

#publish_dateObject

alias



68
69
70
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 68

def publish_date # alias
  first_retrieve
end

#size_highObject



83
84
85
86
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 83

def size_high
  return nil if @hash == nil
  @hash['size_high'].to_i
end

#size_lowObject



88
89
90
91
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 88

def size_low
  return nil if @hash == nil
  @hash['size_low'].to_i
end

#tagsObject



138
139
140
141
142
143
144
145
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 138

def tags
  return nil if @hash.nil? || @hash['tags'].nil?
  xml = @xml.scan(/\<tags domain=\"jp\">\n.+\<\/tags\>/m)[0]
  parsed = Nokogiri::XML xml
  parsed.xpath("//tag").map do |tag_object|
    generate_tag_hash_by tag_object
  end
end

#thumb_typeObject



123
124
125
126
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 123

def thumb_type
  return nil if @hash == nil
  @hash['thumb_type']
end

#thumbnail_urlObject



58
59
60
61
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 58

def thumbnail_url
  return nil if @hash == nil
  @hash['thumbnail_url']
end

#titleObject



48
49
50
51
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 48

def title
  return nil if @hash == nil
  @hash['title']
end

#urlObject



113
114
115
116
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 113

def url
  return nil if @hash == nil
  @hash['watch_url']
end

#user_idObject



147
148
149
150
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 147

def user_id
  return nil if @hash == nil
  @hash['user_id'].to_i
end

#video_idObject



43
44
45
46
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 43

def video_id
  return nil if @hash == nil
  @hash['video_id']
end

#view_counterObject



93
94
95
96
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 93

def view_counter
  return nil if @hash.nil? || @hash['view_counter'].nil?
  @hash['view_counter'].to_i
end

#watch_urlObject



118
119
120
121
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 118

def watch_url
  return nil if @hash == nil
  @hash['watch_url']
end