Class: Manifique::Metadata
- Inherits:
-
Object
- Object
- Manifique::Metadata
- Defined in:
- lib/manifique/metadata.rb
Instance Attribute Summary collapse
-
#background_color ⇒ Object
Returns the value of attribute background_color.
-
#description ⇒ Object
Returns the value of attribute description.
-
#display ⇒ Object
Returns the value of attribute display.
-
#from_html ⇒ Object
Returns the value of attribute from_html.
-
#from_web_manifest ⇒ Object
Returns the value of attribute from_web_manifest.
-
#icons ⇒ Object
Returns the value of attribute icons.
-
#name ⇒ Object
Returns the value of attribute name.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#share_target ⇒ Object
Returns the value of attribute share_target.
-
#short_name ⇒ Object
Returns the value of attribute short_name.
-
#start_url ⇒ Object
Returns the value of attribute start_url.
-
#theme_color ⇒ Object
Returns the value of attribute theme_color.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ Metadata
constructor
A new instance of Metadata.
- #load_from_html(html) ⇒ Object
- #load_from_web_manifest(manifest) ⇒ Object
- #select_icon(options = {}) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Metadata
Returns a new instance of Metadata.
9 10 11 12 13 14 |
# File 'lib/manifique/metadata.rb', line 9 def initialize(data={}) self.url = data[:url] self.from_web_manifest = Set.new self.from_html = Set.new self.icons = [] end |
Instance Attribute Details
#background_color ⇒ Object
Returns the value of attribute background_color.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def background_color @background_color end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def description @description end |
#display ⇒ Object
Returns the value of attribute display.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def display @display end |
#from_html ⇒ Object
Returns the value of attribute from_html.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def from_html @from_html end |
#from_web_manifest ⇒ Object
Returns the value of attribute from_web_manifest.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def from_web_manifest @from_web_manifest end |
#icons ⇒ Object
Returns the value of attribute icons.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def icons @icons end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def name @name end |
#scope ⇒ Object
Returns the value of attribute scope.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def scope @scope end |
#share_target ⇒ Object
Returns the value of attribute share_target.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def share_target @share_target end |
#short_name ⇒ Object
Returns the value of attribute short_name.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def short_name @short_name end |
#start_url ⇒ Object
Returns the value of attribute start_url.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def start_url @start_url end |
#theme_color ⇒ Object
Returns the value of attribute theme_color.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def theme_color @theme_color end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/manifique/metadata.rb', line 4 def url @url end |
Instance Method Details
#load_from_html(html) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/manifique/metadata.rb', line 26 def load_from_html(html) @html = html parse_title_from_html parse_display_mode_from_html parse_icons_from_html end |
#load_from_web_manifest(manifest) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/manifique/metadata.rb', line 16 def load_from_web_manifest(manifest) [ :name, :short_name, :description, :icons, :theme_color, :background_color, :display, :start_url, :scope, :share_target ].map(&:to_s).each do |prop| next unless manifest[prop] && !manifest[prop].to_s.empty? self.send("#{prop}=", manifest[prop]) self.from_web_manifest.add(prop) end end |
#select_icon(options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/manifique/metadata.rb', line 34 def select_icon(={}) if [:type].nil? && [:sizes].nil? && [:purpose].nil? raise ArgumentError, "Tell me what to do!" end results = icons.dup if [:purpose] results.reject! { |r| r["purpose"] != [:purpose] } end if [:type] if [:type].is_a?(String) results.reject! { |r| r["type"] != [:type] } elsif [:type].is_a?(Regexp) results.reject! { |r| r["type"].match([:type]).nil? } else raise ArgumentError, "Type must be a string or a regular expression" end end if [:sizes] results.reject! { |r| r["sizes"].nil? || r["sizes"].match(/(\d+)x/).nil? } results.sort! { |a, b| sizes_to_i(b["sizes"]) <=> sizes_to_i(a["sizes"]) } if icon = select_exact_size(results, [:sizes]) return icon else return select_best_size(results, [:sizes]) end end results.first end |
#to_json ⇒ Object
69 70 71 |
# File 'lib/manifique/metadata.rb', line 69 def to_json # TODO serialize into JSON end |