Class: NicoQuery::ObjectMapper::MylistRSS

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

Direct Known Subclasses

TagSearchRss

Defined Under Namespace

Classes: Item, Meta

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ MylistRSS

Returns a new instance of MylistRSS.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nicoquery/object_mapper/mylist_rss.rb', line 9

def initialize(xml)
  @parser = Nori.new
  @parsed_xml = @parser.parse xml
  entire = @parsed_xml['rss']['channel']

  @meta = Meta.new entire, title_prefix
  if entire['item'].is_a? Array
    @items = entire['item'].map { |item| Item.new item }
  elsif entire['item'].nil?
    @items = []
  else
  # noriは子要素が複数の場合は配列に変換するが、1つの場合には配列にしない。
  # しかし、MylistRSSはitemsが配列であること前提にしているので、item要素が
  # 1つだけの場合にも配列に変換する必要がある。
    @items = [ Item.new(entire['item']) ]
  end
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



7
8
9
# File 'lib/nicoquery/object_mapper/mylist_rss.rb', line 7

def items
  @items
end

#metaObject (readonly)

Returns the value of attribute meta.



7
8
9
# File 'lib/nicoquery/object_mapper/mylist_rss.rb', line 7

def meta
  @meta
end

Instance Method Details

#title_prefixObject



27
28
29
# File 'lib/nicoquery/object_mapper/mylist_rss.rb', line 27

def title_prefix
  "マイリスト"
end