Class: NicoQuery::ObjectMapper::VideoArray
- Inherits:
-
Object
- Object
- NicoQuery::ObjectMapper::VideoArray
- Defined in:
- lib/nicoquery/object_mapper/video_array.rb
Defined Under Namespace
Classes: Video
Instance Attribute Summary collapse
-
#movies ⇒ Object
readonly
Returns the value of attribute movies.
Instance Method Summary collapse
-
#initialize(xml) ⇒ VideoArray
constructor
A new instance of VideoArray.
Constructor Details
#initialize(xml) ⇒ VideoArray
Returns a new instance of VideoArray.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nicoquery/object_mapper/video_array.rb', line 10 def initialize(xml) parser = Nori.new parsed_xml = parser.parse xml entire = parsed_xml['nicovideo_video_response'] if entire['video_info'].is_a? Array @movies = entire['video_info'].each_with_object([]) do |movie, array| array << Video.new(movie) end elsif entire['video_info'].nil? @movies = [] else # noriは子要素が複数の場合は配列に変換するが、1つの場合には配列にしない。 # しかし、MylistRSSはitemsが配列であること前提にしているので、item要素が # 1つだけの場合にも配列に変換する必要がある。 @movies = [ Video.new(entire['video_info']) ] end end |
Instance Attribute Details
#movies ⇒ Object (readonly)
Returns the value of attribute movies.
8 9 10 |
# File 'lib/nicoquery/object_mapper/video_array.rb', line 8 def movies @movies end |