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.



7
8
9
10
11
12
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 7

def initialize(xml)
  @xml = xml
  parser = Nori.new
  parsed_xml = parser.parse xml
  @hash = parsed_xml['nicovideo_thumb_response']['thumb']
end

Instance Method Details

#comment_numObject



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

def comment_num
  @hash['comment_num'].to_i
end

#descriptionObject



22
23
24
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 22

def description
  @hash['description']
end

#embeddableObject



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

def embeddable
  @hash['embeddable'] == 1
end

#first_retrieveObject



30
31
32
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 30

def first_retrieve
  @hash['first_retrieve'].to_time
end

#generate_tag_hash_by(nokogiri_xml) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 103

def generate_tag_hash_by(nokogiri_xml)
  text = nokogiri_xml.text

  lock = if nokogiri_xml.attributes['lock'].present?
    nokogiri_xml.attributes['lock'].text.to_i == 1
  else
    false
  end

  { text: text, lock: lock }
end

#last_res_bodyObject



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

def last_res_body
  @hash['last_res_body']
end

#lengthObject



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

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

#movie_typeObject



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

def movie_type
  @hash['movie_type']
end

#mylist_counterObject



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

def mylist_counter
  @hash['mylist_counter'].to_i
end

#no_live_playObject



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

def no_live_play
  @hash['no_live_play'] == 1
end

#publish_dateObject

alias



34
35
36
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 34

def publish_date # alias
  first_retrieve
end

#size_highObject



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

def size_high
  @hash['size_high'].to_i
end

#size_lowObject



51
52
53
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 51

def size_low
  @hash['size_low'].to_i
end

#tagsObject



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

def tags
  xml = @xml.scan(/\<tags domain=\"jp\">\n.+\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



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

def thumb_type
  @hash['thumb_type']
end

#thumbnail_urlObject



26
27
28
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 26

def thumbnail_url
  @hash['thumbnail_url']
end

#titleObject



18
19
20
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 18

def title
  @hash['title']
end

#urlObject



71
72
73
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 71

def url
  @hash['watch_url']
end

#user_idObject



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

def user_id
  @hash['user_id'].to_i
end

#video_idObject



14
15
16
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 14

def video_id
  @hash['video_id']
end

#view_counterObject



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

def view_counter
  @hash['view_counter'].to_i
end

#watch_urlObject



75
76
77
# File 'lib/nicoquery/object_mapper/getthumbinfo.rb', line 75

def watch_url
  @hash['watch_url']
end