Class: Mako::SubscriptionListParser

Inherits:
Object
  • Object
show all
Includes:
FileOpenUtil
Defined in:
lib/mako/subscription_list_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileOpenUtil

included, #load_resource

Constructor Details

#initialize(args) ⇒ SubscriptionListParser

Returns a new instance of SubscriptionListParser.



9
10
11
# File 'lib/mako/subscription_list_parser.rb', line 9

def initialize(args)
  @list = args.fetch(:list)
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



7
8
9
# File 'lib/mako/subscription_list_parser.rb', line 7

def list
  @list
end

Instance Method Details

#load_listString

Load the subscription list file

Returns:

  • (String)


30
31
32
# File 'lib/mako/subscription_list_parser.rb', line 30

def load_list
  load_resource(list)
end

#parseArray

Parses OPML, JSON, or plain text documents and returns an Array of feed urls.

Returns:

  • (Array)


16
17
18
19
20
21
22
23
24
25
# File 'lib/mako/subscription_list_parser.rb', line 16

def parse
  case File.extname list
  when '.xml' || '.opml'
    Nokogiri::XML(load_list).xpath('//@xmlUrl').map(&:value)
  when '.json'
    JSON.parse(load_list)
  when '.txt'
    load_list.split("\n")
  end
end