Store manifest props as metadata props

This commit is contained in:
2018-06-29 15:21:28 -07:00
parent 4c0d40bd34
commit b05cad0f3f
4 changed files with 78 additions and 11 deletions

View File

@@ -1,10 +1,22 @@
require 'ostruct'
module Manifique
class Metadata
attr_accessor :manifest
def initialize
attr_accessor :url, :src_web_manifest, :src_html_data,
:name, :short_name, :description, :icons,
:theme_color, :background_color, :display,
:start_url, :scope, :share_target
def initialize(data={})
self.url = data[:url]
end
def web_manifest=(manifest)
[:name, :short_name, :description, :icons,
:theme_color, :background_color, :display,
:start_url, :scope, :share_target].map(&:to_s).each do |prop|
self.send("#{prop}=", manifest[prop]) if manifest[prop]
end
self.src_web_manifest = manifest
end
def to_json

View File

@@ -11,14 +11,14 @@ module Manifique
def initialize(options={})
@options = options
@url = options[:url]
@metadata = Metadata.new
@metadata = Metadata.new(url: @url)
end
def fetch_metadata
fetch_website
manifest = fetch_web_manifest
fetch_web_manifest
if @metadata.manifest = manifest
if @metadata.web_manifest
return @metadata
else
#TODO assemble from HTML elements
@@ -44,7 +44,7 @@ module Manifique
res = do_get_request manifest_url
JSON.parse(res.body) rescue false
@metadata.web_manifest = JSON.parse(res.body) rescue false
end
private