Module: Yarss::Attribute
- Defined in:
- lib/yarss/attribute.rb
Overview
A bunch of helpers to extract a String value out of a Hash, Array, etc.
Class Method Summary collapse
-
.author_value(value) ⇒ String
Extract a
Stringvalue from a given author attribute. -
.link_value(value) ⇒ String
Extract a
Stringvalue from a given link attribute. -
.value(value) ⇒ String
Extract a
Stringvalue from a given attribute.
Class Method Details
.author_value(value) ⇒ String
Extract a String value from a given author attribute.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/yarss/attribute.rb', line 44 def self.(value) value ||= '' case value when Hash value(value.fetch('name')) when String value.strip else raise ParseError, "Unknown #{value.class} attribute: #{value.inspect}" end rescue KeyError => e raise ParseError, e end |
.link_value(value) ⇒ String
Extract a String value from a given link attribute.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/yarss/attribute.rb', line 74 def self.link_value(value) value ||= '' case value when Hash link_value(value.fetch('href')) when Array item = value.find { |l| l.is_a?(String) } || value.find { |l| l['rel'] && l['rel'] == 'self' } || value.find { |l| l['rel'] && l['rel'] == 'alternate' } raise KeyError unless item link_value(item) when String value.strip else raise ParseError, "Unknown #{value.class} attribute: #{value.inspect}" end rescue KeyError => e raise ParseError, e end |
.value(value) ⇒ String
Extract a String value from a given attribute.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/yarss/attribute.rb', line 18 def self.value(value) value ||= '' case value when Hash value(value.fetch('__content__')) when String value.strip else raise ParseError, "Unknown #{value.class} attribute: #{value.inspect}" end rescue KeyError => e raise ParseError, e end |