class Elsmore::Resource

Attributes

emitter[RW]
filename[RW]
parent[RW]
url[RW]

Public Class Methods

new(url, parent) click to toggle source
# File lib/elsmore/resource.rb, line 7
def initialize url, parent
  self.url = Elsmore::Url.new(url, parent)
  self.parent = parent
end

Public Instance Methods

data() click to toggle source
# File lib/elsmore/resource.rb, line 21
def data
  @data ||= HTTParty.get(url.canonical_url)
end
write!(nested_urls = false) click to toggle source
# File lib/elsmore/resource.rb, line 12
def write! nested_urls = false
  process_nested_urls if nested_urls

  writer = Elsmore::Writer.new(self)
  writer.emitter = emitter
  writer.write
  self.filename = writer.canonical_filename
end

Private Instance Methods

process_nested_urls() click to toggle source
# File lib/elsmore/resource.rb, line 27
def process_nested_urls
  urls = data.scan(/url\((.*?)\)/i).map do |match|
    if match[0].start_with?('"') || match[0].start_with?("'")
      match[0][1...-1]
    else
      match[0]
    end
  end

  urls.each do |nested_url|
    resource = Elsmore::Resource.new(nested_url, url)
    resource.emitter = emitter
    resource.write!

    @data.gsub!(nested_url, resource.url.resource_path)
  end
end