Class: OpenGraphPlus::Parser
- Inherits:
-
Object
- Object
- OpenGraphPlus::Parser
- Defined in:
- lib/opengraphplus/parser.rb
Constant Summary collapse
- REQUIRED_TAGS =
%w[og:title og:type og:image og:url].freeze
- RECOMMENDED_TAGS =
%w[og:description og:site_name twitter:card twitter:title twitter:image].freeze
Instance Attribute Summary collapse
-
#html ⇒ Object
readonly
Returns the value of attribute html.
Instance Method Summary collapse
- #[](property) ⇒ Object
- #all_tags ⇒ Object
- #errors ⇒ Object
-
#initialize(html) ⇒ Parser
constructor
A new instance of Parser.
- #og_tags ⇒ Object
- #twitter_tags ⇒ Object
- #valid? ⇒ Boolean
- #warnings ⇒ Object
Constructor Details
#initialize(html) ⇒ Parser
Returns a new instance of Parser.
12 13 14 15 |
# File 'lib/opengraphplus/parser.rb', line 12 def initialize(html) @html = html.to_s @tags = end |
Instance Attribute Details
#html ⇒ Object (readonly)
Returns the value of attribute html.
10 11 12 |
# File 'lib/opengraphplus/parser.rb', line 10 def html @html end |
Instance Method Details
#[](property) ⇒ Object
29 30 31 |
# File 'lib/opengraphplus/parser.rb', line 29 def [](property) @tags[property] end |
#all_tags ⇒ Object
25 26 27 |
# File 'lib/opengraphplus/parser.rb', line 25 def @tags.dup end |
#errors ⇒ Object
37 38 39 |
# File 'lib/opengraphplus/parser.rb', line 37 def errors REQUIRED_TAGS.reject { |tag| @tags.key?(tag) } end |
#og_tags ⇒ Object
17 18 19 |
# File 'lib/opengraphplus/parser.rb', line 17 def @tags.select { |key, _| key.start_with?("og:") } end |
#twitter_tags ⇒ Object
21 22 23 |
# File 'lib/opengraphplus/parser.rb', line 21 def @tags.select { |key, _| key.start_with?("twitter:") } end |
#valid? ⇒ Boolean
33 34 35 |
# File 'lib/opengraphplus/parser.rb', line 33 def valid? errors.empty? end |
#warnings ⇒ Object
41 42 43 |
# File 'lib/opengraphplus/parser.rb', line 41 def warnings RECOMMENDED_TAGS.reject { |tag| @tags.key?(tag) } end |