Class: Mangdown::Page

Inherits:
Object
  • Object
show all
Includes:
Equality
Defined in:
lib/mangdown/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Equality

#<=>, #==, #eql?

Constructor Details

#initialize(name, uri) ⇒ Page

Returns a new instance of Page.



7
8
9
10
# File 'lib/mangdown/page.rb', line 7

def initialize(name, uri)
  @name = name
  @uri  = Mangdown::Uri.new(uri) 
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/mangdown/page.rb', line 5

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/mangdown/page.rb', line 5

def uri
  @uri
end

Instance Method Details

#download_to(dir = Dir.pwd) ⇒ Object

downloads to specified directory



18
19
20
21
22
23
24
# File 'lib/mangdown/page.rb', line 18

def download_to(dir = Dir.pwd)
  return if File.exist?(path = file_path(dir))
  File.open(path, 'wb') { |file| file.write(Tools.get(uri)) }
  FileUtils.mv(path, "#{path}.#{Tools.file_type(path)}")
rescue SocketError => error
  STDERR.puts( "#{error.message} | #{name} | #{uri}" )
end

#file_path(dir) ⇒ Object



26
27
28
# File 'lib/mangdown/page.rb', line 26

def file_path(dir)
  Tools.relative_or_absolute_path(dir, name)
end

#to_pageObject

explicit conversion to page



13
14
15
# File 'lib/mangdown/page.rb', line 13

def to_page
  self
end