Class: Parser::XmlBase

Inherits:
Object
  • Object
show all
Defined in:
lib/fly_parser/xml_base.rb

Direct Known Subclasses

News, NewsAZ, NewsFr, NewsNl

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ XmlBase

Returns a new instance of XmlBase.



3
4
5
6
7
8
9
10
11
# File 'lib/fly_parser/xml_base.rb', line 3

def initialize(source, options = {})
  if options[:type] == :file
    source = fake_url(source)
  end
  @copyright = copyright(options)
  @source = Parser.connect(source)
  @delay ||= options[:source]["delay"] || 10
  @enable_tags = tags(options)
end

Instance Method Details



21
22
23
24
25
26
27
# File 'lib/fly_parser/xml_base.rb', line 21

def copyright(options)
  source = options[:source]
  {
    url: source['copyright'],
    title: source['copyright_title']
  }
end

#fake_url(source) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/fly_parser/xml_base.rb', line 13

def fake_url(source)
  stream = File.read(source)
  # test_file.com is a random url, just for Mechanize parsing
  url = "http://www.google.com"
  FakeWeb.register_uri(:get, url, :body => stream, :content_type => "application/xml")
  url
end

#tags(options) ⇒ Object



29
30
31
32
# File 'lib/fly_parser/xml_base.rb', line 29

def tags(options)
  source = options[:source]
  source['tags']
end