Class: Mangdown::Page
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#download_to(dir = Dir.pwd) ⇒ Object
downloads to specified directory.
- #file_path(dir) ⇒ Object
-
#initialize(name, uri) ⇒ Page
constructor
A new instance of Page.
-
#to_page ⇒ Object
explicit conversion to page.
Methods included from Equality
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/mangdown/page.rb', line 5 def name @name end |
#uri ⇒ Object (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_page ⇒ Object
explicit conversion to page
13 14 15 |
# File 'lib/mangdown/page.rb', line 13 def to_page self end |