Class: Ogo::Parsers::Opengraph
- Defined in:
- lib/ogo/parsers/opengraph.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #description(fallback = false) ⇒ Object
- #image(fallback = false) ⇒ Object
-
#initialize(parseable, fallback = false) ⇒ Opengraph
constructor
A new instance of Opengraph.
- #metadata(fallback = false) ⇒ Object
- #title(fallback = false) ⇒ Object
- #type(fallback = false) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(parseable, fallback = false) ⇒ Opengraph
Returns a new instance of Opengraph.
5 6 7 8 |
# File 'lib/ogo/parsers/opengraph.rb', line 5 def initialize(parseable, fallback=false) @global_fallback = fallback super parseable end |
Instance Method Details
#description(fallback = false) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ogo/parsers/opengraph.rb', line 21 def description(fallback=false) if fallback super else _val = ('description') (!_val.empty? && _val) || (@global_fallback && super) || '' end end |
#image(fallback = false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ogo/parsers/opengraph.rb', line 32 def image(fallback=false) if fallback super else _val = ('image') if _val.empty? (@global_fallback && super) || nil else host_uri = Addressable::URI.parse(url) Ogo::ImageInfo.new(url: fix_image_path(_val, host_uri)) end end end |
#metadata(fallback = false) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ogo/parsers/opengraph.rb', line 57 def (fallback=false) = super if fallback [:fallback] = { title: title(true), description: description(true), type: type(true), image: nil } img = image(true) if img [:fallback][:image] = { url: img.url, width: img.width, height: img.height, type: img.type } end end end |
#title(fallback = false) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ogo/parsers/opengraph.rb', line 10 def title(fallback=false) if fallback super else _val = ('title') (!_val.empty? && _val) || (@global_fallback && super) || '' end end |
#type(fallback = false) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ogo/parsers/opengraph.rb', line 46 def type(fallback=false) if fallback super else _val = ('type') (!_val.empty? && _val) || (@global_fallback && super) || '' end end |