Class: HTMLPackage::Package
- Inherits:
-
Object
- Object
- HTMLPackage::Package
- Defined in:
- lib/html_package/package.rb
Constant Summary collapse
- JAVASCRIPT =
"text/javascript"
- PACKAGE =
"text/package+html"
- SPADE =
"text/spade+javascript"
- PACKAGES =
"[type='#{PACKAGE}']"
- SCRIPTS =
"[type='#{JAVASCRIPT}']"
- SPADES =
"[type='#{SPADE}']"
- SELF =
"[rel='self']"
- DEPENDENCY =
"[rel='dependency']"
- DEVELOPMENT_DEPENDENCY =
"[rel$='dependency']"
Class Method Summary collapse
Instance Method Summary collapse
- #all_files ⇒ Object
- #dependency_files ⇒ Object
- #dependency_packages ⇒ Object
- #find(selector) ⇒ Object
-
#initialize(document, resource_type, development) ⇒ Package
constructor
A new instance of Package.
- #links(*properties) ⇒ Object
- #own_files ⇒ Object
Constructor Details
#initialize(document, resource_type, development) ⇒ Package
Returns a new instance of Package.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/html_package/package.rb', line 26 def initialize(document, resource_type, development) @document = document @resource_type = resource_type @development = development if @development @dependency_type = DEVELOPMENT_DEPENDENCY else @dependency_type = DEPENDENCY end end |
Class Method Details
.open(uri, resource_type = SPADES, development = false) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/html_package/package.rb', line 17 def self.open(uri, resource_type=SPADES, development = false) puts "opening package: #{uri.green}" new Nokogiri::HTML(Kernel.open uri), resource_type, development rescue OpenURI::HTTPError => e puts "failed: GET #{uri.red}" puts " #{e.class.name.bold} #{e..red.bold}" puts end |
Instance Method Details
#all_files ⇒ Object
62 63 64 |
# File 'lib/html_package/package.rb', line 62 def all_files @all_files ||= ( own_files + dependency_files ).uniq end |
#dependency_files ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/html_package/package.rb', line 51 def dependency_files links = [] links += direct_links = links(@dependency_type, @resource_type).map{|link| link[:href]} dependency_packages.each do |package| links += package.all_files end links end |
#dependency_packages ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/html_package/package.rb', line 41 def dependency_packages @dependency_packages ||= begin links(@dependency_type, PACKAGES).map do |package_link| href = package_link[:href] puts "dependency: #{href.blue}" HTMLPackage::Package.open(href, @resource_type, @dependency_type) end end.compact end |
#find(selector) ⇒ Object
70 71 72 |
# File 'lib/html_package/package.rb', line 70 def find(selector) @document.css(selector) end |
#links(*properties) ⇒ Object
66 67 68 |
# File 'lib/html_package/package.rb', line 66 def links(*properties) find ["link"].concat(properties).join end |
#own_files ⇒ Object
37 38 39 |
# File 'lib/html_package/package.rb', line 37 def own_files links(SELF, @resource_type).map{|link| link[:href]} end |